C# 用C语言实现神经网络#

C# 用C语言实现神经网络#,c#,for-loop,neural-network,C#,For Loop,Neural Network,我将在此链接上阅读教程: 我是神经网络的新手,我正在尝试编辑上面教程中的示例以匹配我的问题。我正在使用多元回归来寻找3组不同数据的系数,然后计算每组数据的rsquared值。我正在尝试创建一个神经网络,它将改变系数值,使rsquared值尽可能接近100 这就是我如何建立系数并找到该系数的rsquared值。所有3个系数都使用相同的方法: Calculations calc = new Calculations(); Vector<double> lowRiskCoefficient

我将在此链接上阅读教程:

我是神经网络的新手,我正在尝试编辑上面教程中的示例以匹配我的问题。我正在使用多元回归来寻找3组不同数据的系数,然后计算每组数据的rsquared值。我正在尝试创建一个神经网络,它将改变系数值,使rsquared值尽可能接近100

这就是我如何建立系数并找到该系数的rsquared值。所有3个系数都使用相同的方法:

Calculations calc = new Calculations();
Vector<double> lowRiskCoefficient = MultipleRegression.QR(                                            Matrix<double>.Build.DenseOfColumnArrays(lowRiskShortRatingList.ToArray(), lowRiskMediumRatingList.ToArray(), lowRiskLongRatingList.ToArray()),                                            Vector<double>.Build.Dense(lowRiskWeekReturnList.ToArray()));
                decimal lowRiskShortCoefficient = Convert.ToDecimal(lowRiskCoefficient[0]);
                decimal lowRiskMediumCoefficient = Convert.ToDecimal(lowRiskCoefficient[1]);
                decimal lowRiskLongCoefficient = Convert.ToDecimal(lowRiskCoefficient[2]);
                List<decimal> lowRiskWeekReturnDecimalList = new List<decimal>(lowRiskWeekReturnList.Count);
                lowRiskWeekReturnList.ForEach(i => lowRiskWeekReturnDecimalList.Add(Convert.ToDecimal(i)));
                List<decimal> lowRiskPredictedReturnList = new List<decimal>(lowRiskWeekReturnList.Count);
                List<decimal> lowRiskResidualValueList = new List<decimal>(lowRiskWeekReturnList.Count);
                for (int i = 0; i < lowRiskWeekReturnList.Count; i++)
                {
                    decimal lowRiskPredictedValue = (Convert.ToDecimal(lowRiskShortRatingList.ElementAtOrDefault(i)) * lowRiskShortCoefficient) + (Convert.ToDecimal(lowRiskMediumRatingList.ElementAtOrDefault(i)) * lowRiskMediumCoefficient) +
                        (Convert.ToDecimal(lowRiskLongRatingList.ElementAtOrDefault(i)) * lowRiskLongCoefficient);
                    lowRiskPredictedReturnList.Add(lowRiskPredictedValue);
                    lowRiskResidualValueList.Add(calc.calculateResidual(lowRiskWeekReturnDecimalList.ElementAtOrDefault(i), lowRiskPredictedValue));
                }
                decimal lowRiskTotalSumofSquares = calc.calculateTotalSumofSquares(lowRiskWeekReturnDecimalList, lowRiskWeekReturnDecimalList.Average());
                decimal lowRiskTotalSumofRegression = calc.calculateTotalSumofRegression(lowRiskPredictedReturnList, lowRiskWeekReturnDecimalList.Average());
                decimal lowRiskTotalSumofErrors = calc.calculateTotalSumofErrors(lowRiskResidualValueList);
                decimal lowRiskRSquared = lowRiskTotalSumofRegression / lowRiskTotalSumofSquares;
Calculations calc=新计算();
向量低风险系数=MultipleRegression.QR(矩阵.Build.denseOfColumnArray(低风险ShortRatingList.ToArray(),低风险MediumRatingList.ToArray(),低风险LongRatingList.ToArray()),向量.Build.denseOfColumnArray(低风险WeeKreturnList.ToArray());
十进制低风险系数=转换为十进制(低风险系数[0]);
十进制低风险系数=转换为十进制(低风险系数[1]);
十进制LowRiskLongConficient=转换为十进制(LowRiskConficient[2]);
List lowRiskWeekReturnDecimalList=新列表(lowRiskWeekReturnList.Count);
lowRiskWeekReturnList.ForEach(i=>lowRiskWeekReturnDecimalList.Add(Convert.ToDecimal(i));
List lowRiskPredictedReturnList=新列表(lowRiskWeekReturnList.Count);
List lowRiskResidualValueList=新列表(lowRiskWeekReturnList.Count);
对于(int i=0;i
这是执行培训的示例,我目前正忙于如何更改此示例以匹配我正在尝试的操作

private void button1_Click(object sender, EventArgs e)
{
net = new NeuralNet();
double high, mid, low;
high = .9;
low = .1;
mid = .5; 
// initialize with
//   2 perception neurons
//   2 hidden layer neurons
//   1 output neuron
net.Initialize(1, 2, 2, 1);  
double[][] input = new double[4][];
input[0] = new double[] {high, high};
input[1] = new double[] {low, high};
input[2] = new double[] {high, low};
input[3] = new double[] {low, low};
double[][] output = new double[4][];
output[0] = new double[] { low };
output[1] = new double[] { high };
output[2] = new double[] { high };
output[3] = new double[] { low };
double ll, lh, hl, hh;
int count;
count = 0;
do
{
    count++;
    for (int i = 0; i < 100; i++)
        net.Train(input, output);
    net.ApplyLearning();
    net.PerceptionLayer[0].Output = low;
    net.PerceptionLayer[1].Output = low;
    net.Pulse();
    ll = net.OutputLayer[0].Output;
    net.PerceptionLayer[0].Output = high;
    net.PerceptionLayer[1].Output = low;
    net.Pulse();
    hl = net.OutputLayer[0].Output;
    net.PerceptionLayer[0].Output = low;
    net.PerceptionLayer[1].Output = high;
    net.Pulse();
    lh = net.OutputLayer[0].Output;
    net.PerceptionLayer[0].Output = high;
    net.PerceptionLayer[1].Output = high;
    net.Pulse();
    hh = net.OutputLayer[0].Output;
}
while (hh > mid || lh < mid || hl < mid || ll > mid);
MessageBox.Show((count*100).ToString() + " iterations required for training");
}
private void按钮1\u单击(对象发送者,事件参数e)
{
net=新的NeuralNet();
双高、中、低;
高=.9;
低=.1;
中期=.5;
//初始化为
//2感觉神经元
//2隐层神经元
//1输出神经元
初始化(1,2,2,1);
双精度[]输入=新双精度[4][];
输入[0]=新的双精度[]{high,high};
输入[1]=新的双精度[]{低,高};
输入[2]=新的双[]{高,低};
输入[3]=新的双[]{low,low};
双精度[]输出=新双精度[4][];
输出[0]=新的双精度[]{low};
输出[1]=新的双精度[]{high};
输出[2]=新的双精度[]{high};
输出[3]=新的双精度[]{low};
双ll、lh、hl、hh;
整数计数;
计数=0;
做
{
计数++;
对于(int i=0;i<100;i++)
净列车(输入、输出);
net.ApplyLearning();
net.PerceptionLayer[0]。输出=低;
net.PerceptionLayer[1]。输出=低;
net.Pulse();
ll=net.OutputLayer[0]。输出;
net.PerceptionLayer[0]。输出=高;
net.PerceptionLayer[1]。输出=低;
net.Pulse();
hl=净输出层[0]。输出;
net.PerceptionLayer[0]。输出=低;
net.PerceptionLayer[1]。输出=高;
net.Pulse();
lh=net.OutputLayer[0]。输出;
net.PerceptionLayer[0]。输出=高;
net.PerceptionLayer[1]。输出=高;
net.Pulse();
hh=net.OutputLayer[0]。输出;
}
而(hh>mid | | lhmid);
Show((count*100).ToString()+“训练所需的迭代次数”);
}

我如何使用这些信息创建一个神经网络,以找到系数,该系数的rsquared值将尽可能接近100?

您可以使用在.NET中构建的Neuroph框架,而不是从这里开始使用Neuroph.NET

这是他们为JAVA平台所做的原始Neuroph的轻微转换


希望这对您有所帮助。

您尝试过什么?你遇到了什么特别的问题?你的问题太宽泛了。