I have a problem with binary classification, define a category associated with a specific document, documents are displayed as word style vectors of a word such as a word:
Example:
Document 1 = ["I", "am", "awesome"]
Document 2 = ["I", "am", "great", "great"]
Dictionary:
["I", "am", "awesome", "great"]
So, documents in the form of a vector are as follows:
Document 1 = [1, 1, 1, 0]
Document 2 = [1, 1, 0, 2]
I want to apply a stochastic gradient descent algorithm to this input to "minimize the empirical risk associated with loop loss ."
I searched high and low to see how the stochastic gradient descent algorithm would take input in this form, but I did not find a simple and clear explanation anywhere.
This is the pseudocode from Wikipedia:
Choose an initial vector of parameters w and learning rate \alpha.
Randomly shuffle examples in the training set.
Repeat until an approximate minimum is obtained:
For i=1, 2, ..., n, do:
w := w - alpha DELTA Q_i(w)
Can someone please explain to me how the input that I work fits into this pseudocode?
, :
private List<Point2D> loadData()
{
List<Point2D> data = new ArrayList<>();
data.add(new Point2D.Double(1, 2));
data.add(new Point2D.Double(2, 3));
data.add(new Point2D.Double(3, 4));
data.add(new Point2D.Double(4, 5));
data.add(new Point2D.Double(5, 6));
data.add(new Point2D.Double(6, 7));
return data;
}
:
static double[] x = {2, 4, 6, 8};
static double[] y = {2, 5, 5, 8};
, .
, , , , - , , ?
public static void perceptron(Set<String> globoDict,
Map<String, int[]> trainingPerceptronInput,
Map<String, int[]> testPerceptronInput)
{
Map<Integer,double[]> cached_weights = new HashMap<Integer,double[]>();
final int globoDictSize = globoDict.size();
double[] weights = new double[globoDictSize + 1];
for (int i = 0; i < weights.length; i++)
{
weights[i] = 0.0;
}
int inputSize = trainingPerceptronInput.size();
double[] outputs = new double[inputSize];
final double[][] a = Prcptrn_InitOutpt.initializeOutput(trainingPerceptronInput, globoDictSize, outputs, LABEL);
double globalError;
int iteration = 0;
do
{
iteration++;
globalError = 0;
for (int p = 0; p < inputSize; p++)
{
double output = Prcptrn_CalcOutpt.calculateOutput(THETA, weights, a, p);
double localError = outputs[p] - output;
int i;
for (i = 0; i < a.length; i++)
{
weights[i] += LEARNING_RATE * localError * a[i][p];
}
weights[i] += LEARNING_RATE * localError;
globalError += localError * localError;
}
cached_weights.put( iteration , weights );
System.out.println("Iteration " + iteration + " : RMSE = " + Math.sqrt(globalError / inputSize));
}
while (globalError != 0 && iteration <= MAX_ITER);
int size = globoDictSize + 1;
double[] sums = new double[size];
double[] averages = new double[size];
for (Entry<Integer, double[]> entry : cached_weights.entrySet())
{
double[] value = entry.getValue();
for(int pos=0; pos < size; pos++){
sums[ pos ] += value[ pos ];
}
}
for(int pos=0; pos < size; pos++){
averages[ pos ] = sums[ pos ] / cached_weights.size();
}
System.out.println("\n=======\nDecision boundary equation:");
int i;
for (i = 0; i < a.length; i++)
{
System.out.print(" a");
if (i < 10) System.out.print(0);
System.out.println( i + " * " + weights[i] + " + " );
}
System.out.println(" bias: " + weights[i]);
inputSize = testPerceptronInput.size();
outputs = new double[inputSize];
double[][] z = Prcptrn_InitOutpt.initializeOutput(testPerceptronInput, globoDictSize, outputs, LABEL);
test_output = Prcptrn_CalcOutpt.calculateOutput(THETA, weights, z, TEST_CLASS);
System.out.println("class = " + test_output);
}