<commit_before>package net.seiko_comb.combS8214808.joiss2016.mnist;

import static net.seiko_comb.combS8214808.joiss2016.Vector.$;
import static net.seiko_comb.combS8214808.joiss2016.Vector.zero;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.seiko_comb.combS8214808.joiss2016.Vector;

public class MnistReader {
	private Vector[] w = new Vector[10];

	private List<MnistData> trainList, testList;
	private List<Integer> result = new ArrayList<>();

	public MnistReader(List<MnistData> trainList, List<MnistData> testList) {
		this.trainList = trainList;
		this.testList = testList;
	}

	public void read() {
		for (int i = 0; i < 10; i++) {
			w[i] = zero(28 * 28 + 1);
		}
		Collections.shuffle(trainList);
		double eta = 0.01;
		double c = 5.0 / trainList.size();
		for (MnistData data : trainList) {
			Vector x = $(data.getPixel()).addOne();
			for (int i = 0; i < 10; i++) {
				double y = data.getLabel() == i ? 1 : -1;
				// w[i] = perceptron(w[i], x, y);
				w[i] = Mnist.svm(w[i], x, y, eta, c);
				// w[i] = logistic(w[i], x, y, eta, c);
			}
		}
		double count = 0;
		for (MnistData data : testList) {
			Vector x = $(data.getPixel()).addOne();
			int max = getResult(x);
			if (max == data.getLabel()) {
				count++;
			}
			result.add(max);
		}
		System.out.println(count / testList.size());
	}

	public int getResult(Vector x) {
		double[] score = new double[10];
		for (int i = 0; i < 10; i++) {
			score[i] = w[i].product(x);
		}
		int max = 0;
		for (int i = 1; i < 10; i++) {<commit_msg>コミットし残し<commit_after>package net.seiko_comb.combS8214808.joiss2016.mnist;

import static net.seiko_comb.combS8214808.joiss2016.Vector.$;
import static net.seiko_comb.combS8214808.joiss2016.Vector.zero;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.seiko_comb.combS8214808.joiss2016.Vector;

public class MnistReader {
	private Vector[] w = new Vector[10];

	private List<MnistData> trainList, testList;
	private List<Integer> result = new ArrayList<>();

	public MnistReader(List<MnistData> trainList, List<MnistData> testList) {
		this.trainList = trainList;
		this.testList = testList;
	}

	public void read() {
		for (int i = 0; i < 10; i++) {
			w[i] = zero(28 * 28 + 1);
		}
		Collections.shuffle(trainList);
		double eta = 0.01;
		double c = 5.0 / trainList.size();
		for (MnistData data : trainList) {
			Vector x = $(data.getPixel()).addOne();
			for (int i = 0; i < 10; i++) {
				double y = data.getLabel() == i ? 1 : -1;
				// w[i] = perceptron(w[i], x, y);
				// w[i] = Mnist.svm(w[i], x, y, eta, c);
				// w[i] = logistic(w[i], x, y, eta, c);
			}
		}
		double count = 0;
		for (MnistData data : testList) {
			Vector x = $(data.getPixel()).addOne();
			int max = getResult(x);
			if (max == data.getLabel()) {
				count++;
			}
			result.add(max);
		}
		System.out.println(count / testList.size());
	}

	public int getResult(Vector x) {
		double[] score = new double[10];
		for (int i = 0; i < 10; i++) {
			score[i] = w[i].product(x);
		}
		int max = 0;
		for (int i = 1; i < 10; i++) {
{'fraction_non_alphanumeric': 0.17186997103315094, 'fraction_numerical': 0.04763437399420663, 'mean_word_length': 3.365168539325843, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6021948', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1211, 'n_words': 294}