Constructing GLMs

本文介绍了广义线性模型(GLM)的基本概念,包括普通最小二乘法、逻辑回归及softmax回归,并探讨了如何通过最大似然估计来拟合模型参数。

1. Guide

  More generally, consider a classification or regression problem where we would like to predict the value of some random variable y as a function of x. To derive a GLM for this problem, we will make the following three assumptions about the conditional distribution of y given x and about our model:

  a. y | x; θ ∼ ExponentialFamily(η). I.e., given x and θ, the distribution of y follows some exponential family distribution, with parameter η.

  b. Given x, our goal is to predict the expected value of T(y) given x. In most of our examples, we will have T(y) = y, so this means we would like the prediction h(x) output by our learned hypothesis h to satisfy hθ(x) = E[y|x]. (Note that this assumption is satisfied in the choices for h(x) for both logistic regression and linear regression. For instance, in logistic regression, we had hθ(x) = p(y = 1|x; θ) = 0 · p(y = 0|x; θ) + 1 · p(y = 1|x; θ) = E[y|x; θ].)

  c. The natural parameter η and the inputs x are related linearly: η = θTx. (if η is vector-valued, then ηi = θiTx. θ=(θ1, θ2,...θk)T, θ1, θ2,...θk are all n+1-vectors, the target variable y will be k-vector)

  ---These three assumptions/design choices will allow us to derive a very elegant class of learning algorithms, namely GLMs, that have many desirable properties such as ease of learning.

 

2. Ordinary Least Squares

  Consider the setting where the target variable y (also called the response variable in GLM terminology) is continuous, and we model the conditional distribution of y given x as as a Gaussian N(μ, σ2).

    h(x) = E[y|x; θ]= μ = η = θT x.

 

3. Logistic Regression

  Here we are interested in binary classification, so y ∈ {0, 1}. Given that y is binary-valued, it therefore seems natural to choose the Bernoulli family of distributions to model the conditional distribution of y given x.

    h(x) = E[y|x; θ]= φ = 1/(1 + e−η) = 1/(1 + e−θT x)

  You are previously wondering how we came up with the form of the logistic function 1/(1 + e−z), this gives one answer: Once we assume that y conditioned on x is Bernoulli, it arises as a consequence of the definition of GLMs and exponential family distributions.

  Note: To introduce a little more terminology, the function g giving the distribution’s mean as a function of the natural parameter (g(η) = E[T(y); η]) is called the canonical response function. Its inverse, g−1, is called the canonical link function. Thus, the canonical response function for the Gaussian family is just the identify function; and the canonical response function for the Bernoulli is the logistic function.

 

4. Softmax Regression

  Consider a classification problem in which the response variable y can take on any one of k values, so y ∈ {1 2, . . . , k}.

  To parameterize a multinomial over k possible outcomes, one could use k - 1parameters φ1, . . . , φk-1 specifying the probability of each of the outcomes.

  For notational convenience, we will let φk = 1 − φ− φ ... − φk-1, but we should keep in mind that this is not a parameter, and that it is fully specified by φ1, . . . , φk−1.

  To express the multinomial as an exponential family distribution, we will define T(y) ∈ Rk−1 as follows:

    

  T(y) is now a k − 1 dimensional vector, rather than a real number. We will write (T(y))i to denote the i-th element of the vector T(y).

  We introduce one more very useful piece of notation. An indicator function 1{·} takes on a value of 1 if its argument is true, and 0 otherwise. For example, 1{2 = 3} = 0, and 1{3 = 5 − 2} = 1.So, we can also write the relationship between T(y) and y as (T(y))i = 1{y = i}.

  We have that E[(T(y))i] = P(y = i) = φi.

  We are now ready to show that the multinomial is a member of the exponential family. We have:

    

  This completes our formulation of the multinomial as an exponential family distribution.

  The link function is given (for i = 1, . . . , k) by

    ηi = log(φik)

  For convenience, we have also defined ηk = log(φkk) = 0.

  To invert the link function and derive the response function, we therefore have that:

    

  This will be:

    

  To complete our model, we use Assumption 3, given earlier, that the ηi’s are linearly related to the x’s. So, have ηi = θiTx (for i = 1, . . . , k − 1), where θ1, . . . , θk−1 ∈ Rn+1 are the parameters of our model. For notational convenience, we can also define θk = 0, so that ηk = θkTx = 0, as given previously. Hence, our model assumes that the conditional distribution of y given x is given by

    

  This model, which applies to classification problems where y ∈ {1, . . . , k}, is called softmax regression. It is a generalization of logistic regression.

  Our hypothesis will output:

    

  In other words, our hypothesis will output the estimated probability that p(y = i|x; θ), for every value of i = 1, . . . , k. (Even though hθ(x) as defined above is only k − 1 dimensional, clearly p(y = k|x; θ) can be obtained as 1 − φ− φ ... − φk-1)

  Lastly, lets discuss parameter fitting. Similar to our original derivation of ordinary least squares and logistic regression, if we have a training set of m examples {(x(i), y(i)); i = 1, . . . ,m} and would like to learn the parameters θi of this model, we would begin by writing down the log-likelihood:

    

  We can now obtain the maximum likelihood estimate of the parameters by maximizing l(θ) in terms of θ, using a method such as gradient ascent or Newton’s method.Here, θ is θ12,...,θk-1 are all n+1-vector.

  Note: We can obtain for all GLM Models update rule like:

      

    

转载于:https://www.cnblogs.com/ustccjw/archive/2013/04/14/3020177.html

1)普通用户端(全平台) 音乐播放核心体验: 个性化首页:基于 “听歌历史 + 收藏偏好” 展示 “推荐歌单(每日 30 首)、新歌速递、相似曲风推荐”,支持按 “场景(通勤 / 学习 / 运动)” 切换推荐维度。 播放页功能:支持 “无损音质切换、倍速播放(0.5x-2.0x)、定时关闭、歌词逐句滚动”,提供 “沉浸式全屏模式”(隐藏冗余控件,突出歌词与专辑封面)。 多端同步:自动同步 “播放进度、收藏列表、歌单” 至所有登录设备(如手机暂停后,电脑端打开可继续播放)。 音乐发现与管理: 智能搜索:支持 “歌曲名 / 歌手 / 歌词片段” 搜索,提供 “模糊匹配(如输入‘晴天’联想‘周杰伦 - 晴天’)、热门搜索词推荐”,结果按 “热度 / 匹配度” 排序。 歌单管理:创建 “公开 / 私有 / 加密” 歌单,支持 “批量添加歌曲、拖拽排序、一键分享到社交平台”,系统自动生成 “歌单封面(基于歌曲风格配色)”。 音乐分类浏览:按 “曲风(流行 / 摇滚 / 古典)、语言(国语 / 英语 / 日语)、年代(80 后经典 / 2023 新歌)” 分层浏览,每个分类页展示 “TOP50 榜单”。 社交互动功能: 动态广场:查看 “关注的用户 / 音乐人发布的动态(如‘分享新歌感受’)、好友正在听的歌曲”,支持 “点赞 / 评论 / 转发”,可直接点击动态中的歌曲播放。 听歌排行:个人页展示 “本周听歌 TOP10、累计听歌时长”,平台定期生成 “全球 / 好友榜”(如 “好友中你本周听歌时长排名第 3”)。 音乐圈:加入 “特定曲风圈子(如‘古典音乐爱好者’)”,参与 “话题讨论(如‘你心中最经典的钢琴曲’)、线上歌单共创”。 (2)音乐人端(创作者中心) 作品管理: 音乐上传:支持 “无损音频(FLAC/WAV)+ 歌词文件(LRC)+ 专辑封面” 上传,填写 “歌曲信息
### 构造对象的概念 在编程中,构造对象通常涉及创建类的一个实例并初始化其属性。这一过程通过调用类中的特殊方法——即构造函数来完成。构造函数的主要作用是在对象被创建时执行必要的初始化操作。 #### 面向对象编程中的构造器 在一个典型的面向对象语言(如Java或SystemVerilog)中,可以通过定义一个具有特定名称的构造函数来实现对象的构建[^1]。例如,在引用的内容中提到 `class ClassA` 的定义中隐含了一个构造逻辑的存在。虽然未显式展示,但在实际应用中,构造函数可能类似于以下形式: ```verilog class ClassA; int value; function new(int init_value); this.value = init_value; // 初始化成员变量 endfunction : new endclass ``` 上述代码展示了如何通过 `new` 函数作为构造函数来初始化 `value` 属性。当一个新的 `ClassA` 对象被创建时,会自动调用此构造函数,并传入初始值以设置该对象的状态。 #### 数据结构与算法视角下的对象构造 从数据结构的角度来看,构造对象不仅限于简单的赋值行为,还涉及到复杂的数据管理策略。例如,数组和链表这样的基础数据结构可以用来表示更高级别的抽象数据类型,比如栈、队列或者二叉树等[^2]。这些复杂的结构往往也需要在其内部维护状态信息,因此它们的构造过程可能会更加复杂。 考虑下面这个例子,它演示了如何使用Python来构造一个基于列表实现的堆栈对象: ```python class Stack: def __init__(self): # 这是一个构造函数 self.items = [] # 初始化为空列表 def push(self, item): self.items.append(item) def pop(self): return self.items.pop() stack_instance = Stack() # 创建Stack的对象 stack_instance.push(10) print(stack_instance.pop()) # 输出最后压入的元素 ``` 在这个案例里,`__init__()` 方法扮演着构造函数的角色,负责建立新的 `Stack` 实例及其关联的存储空间。 #### 动态链接库(DLLs)上下文中对象的构造注意事项 如果讨论的是动态链接库环境下的对象构造,则需要注意额外的因素,例如依赖关系管理和权限问题。假如遇到错误消息 `"Cannot open DllXYZ.dll for writing"` ,这表明可能存在文件访问冲突或者是缺少某些运行所需的外部DLL支持等问题[^4]。解决这类情况需要确保所有必需的组件都已正确定位并且可由应用程序加载。 ### 总结 综上所述,无论在哪种具体的编程场景下,“如何构造一个对象”的答案都会围绕几个核心要素展开:一是明确目标类型的特性;二是合理设计用于启动新实体生命周期的操作序列;三是妥善处理任何可能出现的技术障碍。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值