(main): tests, perceptron adjustments
parent
a09f342fa5
commit
f95bb376b9
Binary file not shown.
|
|
@ -6,18 +6,16 @@ import java.util.*;
|
|||
public class Detector {
|
||||
|
||||
private static final int WEIGHTS_COUNT = 500;
|
||||
private static final int EPOCH_SIZE = 5;
|
||||
private static final int EPOCH_SIZE = 10;
|
||||
private static final double SCALE = 1000.0;
|
||||
private static final int SKIP_TOP = 50;
|
||||
private static final int SKIP_TOP = 60;
|
||||
private static final String modelOutputFile = "modelData.bin";
|
||||
private int genreCount;
|
||||
public Map<String, double[]> modelData;
|
||||
public Set<String> vocabulary;
|
||||
|
||||
/**
|
||||
* Starts the training with provided data
|
||||
* @param csvPath path of the csv containing all texts
|
||||
* @return created weights for each genre + bias
|
||||
*/
|
||||
public Detector(String csvPath) {
|
||||
// Build common vocabulary
|
||||
|
|
@ -37,7 +35,7 @@ public class Detector {
|
|||
Map<String, List<TextCounts>> trainingCounts = GenreData.countTrainData(genreData, vocabulary);
|
||||
modelData = new LinkedHashMap<>();
|
||||
|
||||
genreCount = 0;
|
||||
int genreCount = 0;
|
||||
// Loop all genres
|
||||
for(Map.Entry<String, List<TextCounts>> genres : trainingCounts.entrySet()){
|
||||
double[] currWeights = trainModel(trainingCounts, genres.getKey(), genreCount);
|
||||
|
|
@ -52,7 +50,6 @@ public class Detector {
|
|||
* Starts the training with already trained data
|
||||
* @param csvPath path of the csv containing all texts
|
||||
* @param modelPath path of the .bin file containing training data
|
||||
* @return created weights for each genre + bias
|
||||
*/
|
||||
public Detector(String csvPath, String modelPath) {
|
||||
// Build common vocabulary
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class DetectorTests {
|
|||
|
||||
double[] weigths = {0.1d, 0.0d, -1.2d, 3.4d, 5.0d,9d, 0.0d};
|
||||
double bias = 0.0d;
|
||||
double sum = -0.11d;
|
||||
double sum = 1250.0d;
|
||||
assertEquals(sum, Detector.calcSum(textCounts, weigths, bias));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
package genredct;
|
||||
|
||||
import de.nicode3141.genredct.GenreData;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class GenreDataTests {
|
||||
|
||||
@DisplayName("Test Training Word Count against vocabulary")
|
||||
@Test
|
||||
public void testCountTrainInputString(){
|
||||
Set<String> vocabulary = new HashSet<>();
|
||||
vocabulary.add("the");
|
||||
vocabulary.add("suspects");
|
||||
vocabulary.add("nobody");
|
||||
vocabulary.add("a");
|
||||
vocabulary.add("another");
|
||||
vocabulary.add("after");
|
||||
|
||||
List<String> texts = new ArrayList<>();
|
||||
texts.add("The locked room held three suspects, yet nobody held keys.");
|
||||
Map<String, List<String>> textGenres = new HashMap<>();
|
||||
textGenres.put("mystery", texts);
|
||||
|
||||
Map <String, Integer> expectedWordCount = new HashMap<>();
|
||||
expectedWordCount.put("the", 1);
|
||||
expectedWordCount.put("suspects", 1);
|
||||
expectedWordCount.put("nobody", 1);
|
||||
expectedWordCount.put("a", 0);
|
||||
expectedWordCount.put("another", 0);
|
||||
expectedWordCount.put("after", 0);
|
||||
|
||||
List<Map<String, Integer>> expectedWordCounts = new ArrayList<>();
|
||||
expectedWordCounts.add(expectedWordCount);
|
||||
Map<String, List<Map<String, Integer>>> expected = new HashMap<>();
|
||||
expected.put("mystery", expectedWordCounts);
|
||||
|
||||
assertEquals(expected, GenreData.countTrainData(textGenres, vocabulary));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue