我想對他們的資格和價格進行分類。我應該用MLP來做,但是除了XOR例子之外沒有其他的例子。我有6個條件,我把它們翻倍爲[1,0,0,0]爲vhigh。(條件在我連接的uci集合中。)如何使用MLP進行汽車評估?
這是我的MLP代碼,我想使用uci數據集對它進行訓練Dataset我該如何適應此代碼?
編輯:讓我更清楚我並不是說除XOR問題外沒有任何其他例子。我的意思是我需要一個輸入集的例子,不像[1,0]我需要超過2個輸入。
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class MultiLayerPerceptron implements Cloneable
{
protected double fLearningRate = 0.6;
protected Layer[] fLayers;
protected TransferFunction fTransferFunction;
public MultiLayerPerceptron(int[] layers, double learningRate, TransferFunction fun)
{
fLearningRate = learningRate;
fTransferFunction = fun;
fLayers = new Layer[layers.length];
for(int i = 0; i < layers.length; i++)
{
if(i != 0)
{
fLayers[i] = new Layer(layers[i], layers[i - 1]);
}
else
{
fLayers[i] = new Layer(layers[i], 0);
}
}
}
public double[] execute(double[] input)
{
int i;
int j;
int k;
double new_value;
double output[] = new double[fLayers[fLayers.length - 1].Length];
// Put input
for(i = 0; i < fLayers[0].Length; i++)
{
fLayers[0].Neurons[i].Value = input[i];
}
// Execute - hiddens + output
for(k = 1; k < fLayers.length; k++)
{
for(i = 0; i < fLayers[k].Length; i++)
{
new_value = 0.0;
for(j = 0; j < fLayers[k - 1].Length; j++)
new_value += fLayers[k].Neurons[i].Weights[j] * fLayers[k - 1].Neurons[j].Value;
new_value += fLayers[k].Neurons[i].Bias;
fLayers[k].Neurons[i].Value = fTransferFunction.evalute(new_value);
}
}
// Get output
for(i = 0; i < fLayers[fLayers.length - 1].Length; i++)
{
output[i] = fLayers[fLayers.length - 1].Neurons[i].Value;
}
return output;
}
public double backPropagateMultiThread(double[] input, double[] output, int nthread)
{
return 0.0;
}
public double backPropagate(double[] input, double[] output)
{
double new_output[] = execute(input);
double error;
int i;
int j;
int k;
/* doutput = correct output (output) */
for(i = 0; i < fLayers[fLayers.length - 1].Length; i++)
{
error = output[i] - new_output[i];
fLayers[fLayers.length - 1].Neurons[i].Delta = error * fTransferFunction.evaluteDerivate(new_output[i]);
}
for(k = fLayers.length - 2; k >= 0; k--)
{
//delta
for(i = 0; i < fLayers[k].Length; i++)
{
error = 0.0;
for(j = 0; j < fLayers[k + 1].Length; j++)
error += fLayers[k + 1].Neurons[j].Delta * fLayers[k + 1].Neurons[j].Weights[i];
fLayers[k].Neurons[i].Delta = error * fTransferFunction.evaluteDerivate(fLayers[k].Neurons[i].Value);
}
// success
for(i = 0; i < fLayers[k + 1].Length; i++)
{
for(j = 0; j < fLayers[k].Length; j++)
fLayers[k + 1].Neurons[i].Weights[j] += fLearningRate * fLayers[k + 1].Neurons[i].Delta *
fLayers[k].Neurons[j].Value;
fLayers[k + 1].Neurons[i].Bias += fLearningRate * fLayers[k + 1].Neurons[i].Delta;
}
}
// error
error = 0.0;
for(i = 0; i < output.length; i++)
{
error += Math.abs(new_output[i] - output[i]);
//System.out.println(output[i]+" "+new_output[i]);
}
error = error/output.length;
return error;
}
public boolean save(String path)
{
try
{
FileOutputStream fout = new FileOutputStream(path);
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(this);
oos.close();
}
catch (Exception e)
{
return false;
}
return true;
}
public static MultiLayerPerceptron load(String path)
{
try
{
MultiLayerPerceptron net;
FileInputStream fin = new FileInputStream(path);
ObjectInputStream oos = new ObjectInputStream(fin);
net = (MultiLayerPerceptron) oos.readObject();
oos.close();
return net;
}
catch (Exception e)
{
return null;
}
}
public double getLearningRate()
{
return fLearningRate;
}
public void setLearningRate(double rate)
{
fLearningRate = rate;
}
public void setTransferFunction(TransferFunction fun)
{
fTransferFunction = fun;
}
public int getInputLayerSize()
{
return fLayers[0].Length;
}
public int getOutputLayerSize()
{
return fLayers[fLayers.length - 1].Length;
}
}
有數百個,如果而不是在互聯網上使用神經網絡的數千例子。聲稱他們都是關於異或是一個巨大的誤解。 – lejlot
可以給我一個他們的鏈接嗎?當我試圖找到任何這樣的例子,我只發現像XOR [1,0]兩種輸入類型。如果你知道任何其他例子,你能告訴我這可能是非常有用的。 thx – medemir