C#简单的随机梯度下降算法

这是一个使用C#编写的简单随机梯度下降算法示例,用于求解线性回归模型的权重参数。程序初始化随机权重,通过迭代更新权重以最小化代价函数,直至达到预设的精度阈值。
摘要由CSDN通过智能技术生成
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GrandientDescent
{
    class Program
    {
        static void Main(string[] args)
        {
            //each element in x represents (x0,x1,x2)
            Double[,] X = new Double[5, 3] { { 1, 0.0, 3 }, { 1, 1.0, 3 }, { 1, 2.0, 3 }, { 1, 3.0, 2 }, { 1, 4.0, 4 } };
            //y[i] is the output of y = theta0 * x[0] + theta1 * x[1] +theta2 * x[2]+theta3
            Double[] Y = new Double[5] { 95.364, 97.217205, 75.195834, 60.105519, 49.342380 };
            /*
             parameter::theta待求的权值
             parameter::alpha学习速率
             parameter::m 样本总数 此处m = 10
             parameter::max_iter 最大迭代次数
             */
            double epsilon = 0.000001;
            Random ra
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值