1.1.15. Passive Aggressive Algorithms(被动攻击算法)

1.1.15. Passive Aggressive Algorithms

一、简介:

被动攻击算法体现出了一种在线学习(online learning)的思想。

之前在逻辑回归一章我们讨论过将分类问题转化为回归问题的方式。里面有两个核心关键词:可能性(程度)和可能性(概率)。

在这里,我们对模型的优化从两点考虑。

  1. 样本是否分类正确
  2. 模型预测的可能性(程度/概率)是否贴近实际。

Passive Aggressive Algorithms算法根据以上的判断准则优化自己的模型:

  1. 在样本分类正确 且 模型对可能性的预测准确(程度大于一)时,模型不做调整(这里体现出了被动)
  2. 在样本分类正确 但 模型对可能性的预测有失偏颇(不太准确)时,模型做出轻微的调整
  3. 在样本分类错误时,模型做出较大的调整(体现出较强的“攻击性”)

二、具体实现

在这里插入图片描述

这里引用的是skearn里提供的文献“Online Passive-Aggressive Algorithms” K. Crammer, O. Dekel, J. Keshat, S. Shalev-Shwartz, Y. Singer - JMLR 7 (2006)

我们拿PA来举例。首先将目光投向损失函数(suffur loss) max{ 0,1−yt(ωt⋅xt)}max\{0, 1-y_t(\omega_t\cdot x_t)\}max{ 0,1yt(ωtx

### 解决方案概述 当遇到 `Kotlin` 模块编译版本不兼容的问题时,通常是因为项目中的 `Kotlin` 版本与其依赖项之间的二进制元数据版本存在差异。此问题可以通过调整项目的构建文件来解决。 以下是具体的解决方案: #### 1. 修改 Gradle 文件中的 Kotlin 插件版本 在项目的根目录下的 `build.gradle` 或者模块级别的 `build.gradle` 中找到 `kotlin` 插件的相关配置,并将其更新到与期望的元数据版本匹配的插件版本[^3]。例如,如果目标是使元数据版本为 `1.1.15`,则可以尝试设置如下所示的版本号: ```gradle plugins { id 'org.jetbrains.kotlin.android' version '1.1.15' } ``` 或者,在旧版的 `Gradle` 配置中可能需要这样指定: ```gradle buildscript { ext.kotlin_version = '1.1.15' repositories { google() mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } apply plugin: 'kotlin-android' ``` #### 2. 同步并清理缓存 完成上述更改之后,执行以下命令以同步新的依赖关系并清除任何可能导致冲突的本地缓存数据[^4]: ```bash ./gradlew clean build --refresh-dependencies ``` 对于 Android Studio 用户来说,也可以通过 IDE 的菜单选项实现这些操作: - **File -> Invalidate Caches / Restart** - 然后再点击 **Sync Now** 来重新加载修改后的 `Gradle` 脚本。 #### 3. 更新其他相关库至一致版本 除了核心的 `Kotlin` 编译器外,还需要确认所有使用的第三方库也支持相同的 `Kotlin` 版本。某些情况下,特定版本的库可能会强制绑定更高或更低的 `Kotlin` SDK 版本,因此建议查阅官方文档或仓库说明页面获取最新信息[^2]。 --- ### 示例代码片段展示如何正确配置 Build Script 假设当前环境仅允许使用较老版本的 `Kotlin (v1.1.x)` ,那么完整的 `build.gradle` 可能看起来像这样: ```gradle // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.1.15' repositories { jcenter() // Deprecated but still works for older versions google() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() google() } } task clean(type: Delete) { delete rootProject.buildDir } ``` 同时确保应用级 `build.gradle` 如下定义: ```gradle apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 26 defaultConfig { minSdkVersion 19 targetSdkVersion 26 ... } sourceSets { main.java.srcDirs += 'src/main/kotlin' } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' } ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值