/** * Converts a value into a form that would help a human understand the internals of how the value * is being interpreted. For text-like things, this is likely to be a list of the terms found with * associated weights (if any). * * @param originalForm The original form of the value as a string. * @return A string that a human can read. */ @Override public String asString(String originalForm) { return String.format(Locale.ENGLISH, "%s:%s:%.4f", getName(), originalForm, weight(bytesForString(originalForm))); }
@Override protected int hashForProbe(byte[] originalForm, int dataSize, String name, int probe) { return hash(nameBytes, originalForm, WORD_LIKE_VALUE_HASH_SEED + probe, dataSize); }
/** * Adds a value to a vector. * * @param originalForm The original form of the value as a string. * @param data The vector to which the value should be added. */ @Override public void addToVector(byte[] originalForm, double w, Vector data) { int probes = getProbes(); String name = getName(); double weight = getWeight(originalForm, w); for (int i = 0; i < probes; i++) { int n = hashForProbe(originalForm, data.size(), name, i); if (isTraceEnabled()) { trace(originalForm, n); } data.set(n, data.get(n) + weight); } }
@Test public void testAddToVector() { WordValueEncoder wv = new StaticWordValueEncoder("word"); ContinuousValueEncoder cv = new ContinuousValueEncoder("cont"); InteractionValueEncoder enc = new InteractionValueEncoder("interactions", wv, cv); Vector v1 = new DenseVector(200); enc.addInteractionToVector("a","1.0",1.0, v1); int k = enc.getProbes(); // should set k distinct locations to 1 assertEquals((float) k, v1.norm(1), 0); assertEquals(1.0, v1.maxValue(), 0); // adding same interaction again should increment weights enc.addInteractionToVector("a","1.0",1.0,v1); assertEquals((float) k*2, v1.norm(1), 0); assertEquals(2.0, v1.maxValue(), 0); Vector v2 = new DenseVector(20000); enc.addInteractionToVector("a","1.0",1.0,v2); wv.addToVector("a", v2); cv.addToVector("1.0", v2); k = enc.getProbes(); //this assumes no hash collision assertEquals((float) (k + wv.getProbes()+cv.getProbes()), v2.norm(1), 1.0e-3); }
/** * Adds a value to a vector. * * @param originalForm The original form of the value as a string. * @param data The vector to which the value should be added. */ @Override public void addToVector(String originalForm, double weight, Vector data) { dictionary.add(originalForm); super.addToVector(originalForm, weight, data); }
protected WordValueEncoder(String name) { super(name, 2); nameBytes = bytesForString(name); }
@Override protected double getWeight(byte[] originalForm, double w) { return w * weight(originalForm); }
/** * Adds a value to a vector. * * @param originalForm The original form of the value as a string. * @param data The vector to which the value should be added. */ @Override public void addToVector(byte[] originalForm, double w, Vector data) { int probes = getProbes(); String name = getName(); double weight = getWeight(originalForm, w); for (int i = 0; i < probes; i++) { int n = hashForProbe(originalForm, data.size(), name, i); if (isTraceEnabled()) { trace(originalForm, n); } data.set(n, data.get(n) + weight); } }
/** * Adds a value to a vector. * * @param originalForm The original form of the value as a string. * @param data The vector to which the value should be added. */ @Override public void addToVector(String originalForm, double weight, Vector data) { dictionary.add(originalForm); super.addToVector(originalForm, weight, data); }
protected WordValueEncoder(String name) { super(name, 2); nameBytes = bytesForString(name); }
@Override protected double getWeight(byte[] originalForm, double w) { return w * weight(originalForm); }
/** * Adds a value to a vector. * * @param originalForm The original form of the value as a string. * @param data The vector to which the value should be added. */ @Override public void addToVector(byte[] originalForm, double w, Vector data) { int probes = getProbes(); String name = getName(); double weight = getWeight(originalForm, w); for (int i = 0; i < probes; i++) { int n = hashForProbe(originalForm, data.size(), name, i); if (isTraceEnabled()) { trace(originalForm, n); } data.set(n, data.get(n) + weight); } }
/** * Converts a value into a form that would help a human understand the internals of how the value * is being interpreted. For text-like things, this is likely to be a list of the terms found with * associated weights (if any). * * @param originalForm The original form of the value as a string. * @return A string that a human can read. */ @Override public String asString(String originalForm) { return String.format(Locale.ENGLISH, "%s:%s:%.4f", getName(), originalForm, weight(bytesForString(originalForm))); }
/** * Adds a value to a vector. * * @param originalForm The original form of the value as a string. * @param data The vector to which the value should be added. */ @Override public void addToVector(String originalForm, double weight, Vector data) { dictionary.add(originalForm); super.addToVector(originalForm, weight, data); }
@Override protected int hashForProbe(byte[] originalForm, int dataSize, String name, int probe) { return hash(nameBytes, originalForm, WORD_LIKE_VALUE_HASH_SEED + probe, dataSize); }
protected WordValueEncoder(String name) { super(name, 2); nameBytes = bytesForString(name); }
@Override protected double getWeight(byte[] originalForm, double w) { return w * weight(originalForm); }
/** * Converts a value into a form that would help a human understand the internals of how the value * is being interpreted. For text-like things, this is likely to be a list of the terms found with * associated weights (if any). * * @param originalForm The original form of the value as a string. * @return A string that a human can read. */ @Override public String asString(String originalForm) { return String.format(Locale.ENGLISH, "%s:%s:%.4f", getName(), originalForm, weight(bytesForString(originalForm))); }
@Override protected int hashForProbe(byte[] originalForm, int dataSize, String name, int probe) { return hash(nameBytes, originalForm, WORD_LIKE_VALUE_HASH_SEED + probe, dataSize); }