public WordVector(WordVector orig) : this(modshogunPINVOKE.new_WordVector__SWIG_5(WordVector.getCPtr(orig)), true) { if (modshogunPINVOKE.SWIGPendingException.Pending) { throw modshogunPINVOKE.SWIGPendingException.Retrieve(); } }
public CustomBitArray CalculateHashScore(WordVector vector) { CustomBitArray arr = new CustomBitArray(_hyperPlanes.Count); for (int i = _hyperPlanes.Count - 1; i != -1; i--) arr[i] = (_hyperPlanes[i] * vector) >= 0; return arr; }
public void TestVectorAverage() { var x = new WordVector("word1", new float[] { 1, 3, 4 }); var y = new WordVector("word2", new float[] { 1, 0, 0 }); var result = new[] { x, y }.Average(); CollectionAssert.AreEqual(new [] { 1, 1.5f, 2 }, result); }
public void TestVectorSubtractionOperator() { var x = new WordVector("word1", new float[] { 1, 3, 4 }); var y = new WordVector("word2", new float[] { 1, 0, 0 }); var z = y + x - y; Assert.IsNotNull(z); CollectionAssert.AreEqual(new float[] { 1, 3, 4 }, z); }
public CustomBitArray CalculateHashScore(WordVector vector, out bool anyTrue) { anyTrue = false; CustomBitArray arr = new CustomBitArray(_hyperPlanes.Count); for (int i = _hyperPlanes.Count - 1; i != -1; i--) { anyTrue |= (arr[i] = (_hyperPlanes[i] * vector) > 0); } return arr; }
public TrainingAction(IPlan plan, ContextMaps maps) : base(plan,maps) { _contextMap = maps.For(plan.Word); _weights = _contextMap.NeuronWeights; if (!plan.Output.HasValue) throw new ArgumentException("plan.Output must be set", "plan"); _wordVector = _vectors[plan.Word]; if (_outputArray == null) { _outputArray = OutputToArray(plan.Output.Value); } }
public static short[] get_vector(WordVector src) { IntPtr ptr = modshogunPINVOKE.WordVector_get_vector__SWIG_1(WordVector.getCPtr(src)); if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve(); int[] size = new int[1]; Marshal.Copy(ptr, size, 0, 1); int len = size[0]; short[] ret = new short[len]; Marshal.Copy(new IntPtr(ptr.ToInt64() + Marshal.SizeOf(typeof(int))), ret, 0, len); return ret; }
public void SendQuery(string query) { var n1GrammQuery = TextConvertor.TextToWordList(query); var texts = TextSearcher.Search(query); foreach (string text in texts) { var n1GrammText = TextConvertor.TextToWordList(text); var vectorizedText = _word2VecModelDB.CreateWordVectorList(n1GrammText); var vectorizedQuery = _word2VecModelDB.CreateWordVectorList(n1GrammQuery); var score = Cluster.GetAccordance(WordVector.GetVectors(vectorizedText), WordVector.GetVectors(vectorizedQuery)); _view.ShowTextWithScore(text, score); } }
public void TestRandomExcluding() { _target = new WordVectors(10); var wv1 = new WordVector {Name = "wv1" }; var wv2 = new WordVector { Name = "wv2" }; ; var wv3 = new WordVector { Name = "wv3" }; ; var wv4 = new WordVector { Name = "wv4" }; ; _target.TryAdd("wv1", wv1); _target.TryAdd("wv2", wv2); _target.TryAdd("wv3", wv3); _target.TryAdd("wv4", wv4); var result = _target.RandomExcluding(new HashSet<WordVector> {wv1, wv2, wv3}); result.Should().Be(wv4); }
public static short[] get_vector(WordVector src, bool own) { IntPtr ptr = modshogunPINVOKE.WordVector_get_vector__SWIG_0(WordVector.getCPtr(src), own); if (modshogunPINVOKE.SWIGPendingException.Pending) { throw modshogunPINVOKE.SWIGPendingException.Retrieve(); } int[] size = new int[1]; Marshal.Copy(ptr, size, 0, 1); int len = size[0]; short[] ret = new short[len]; Marshal.Copy(new IntPtr(ptr.ToInt64() + Marshal.SizeOf(typeof(int))), ret, 0, len); return(ret); }
public void TestNetwork() { var wordVector = new WordVector() {Name = "test"}; var elements = new[] {0.1, 0.2, 0.3}; elements.CopyTo(wordVector.Elements,0); var context = new[] {0.4, 0.5}; var factory = new NeuralNetworkFactory(); var network = factory.CreateNeuralNetwork(2, 2); var examples = new[] { new Example {Input = new [] {1.0, 0.0}, ExpectedResult = new []{1.0}}, new Example {Input = new [] {0.0, 1.0}, ExpectedResult = new []{1.0}}, new Example {Input = new [] {1.0, 1.0}, ExpectedResult = new []{0.0}}, new Example {Input = new [] {0.0, 0.0}, ExpectedResult = new []{0.0}} }; var error = network.Train(examples,0.1); var result = network.Run(new[] {0.0, 0.0}); result[0].Should().BeLessOrEqualTo(error + 0.1); }
protected WordVector ParseLine(string line) { var fields = line.Split(' '); var name = fields[0]; var elements = new List<double>(); //skip first (name) and last (blank) for (int i = 1; i < fields.Length-1; i++) { var element = fields[i]; try { elements.Add(double.Parse(element)); } catch (FormatException fe) { _trace.TraceData(System.Diagnostics.TraceEventType.Error, 1, "could not parse element: " + element); throw new LoaderException("could not parse element", fe); } } var wv = new WordVector { Name = name, }; elements.CopyTo(wv.Elements); return wv; }
internal static HandleRef getCPtr(WordVector obj) { return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr); }
public bool TryAdd(string key, WordVector value) { return _wordVectorDictionary.TryAdd(key, value); }
public SimpleTweetCluster() { Vector = new WordVector(); }
public static double Distance(this float[] word1, WordVector word2) { return(word1.Distance(word2.Vector)); }
public static float[] Subtract(this float[] word1, WordVector word2) { return(word1.Subtract(word2.Vector)); }
public static float[] Add(this float[] word1, WordVector word2) { return(word1.Add(word2.Vector)); }
public static List <WordDistance> DistanceList(this List <WordVector> wordList, WordVector currentWord) { var distanceList = new List <WordDistance>(); foreach (WordVector word in wordList) { distanceList.Add(new WordDistance(word.Word, word.Distance(currentWord), currentWord.Word)); } return(distanceList); }
LSHashFunction GetNewHashFunction() { //Generate hyper planes List<WordVector> planes = new List<WordVector>(); for (int j = 0; j < Settings.TweetClusterer_TCW_HyperPlaneCount; j++) { WordVector plane = new WordVector(); List<long> wordIDs = GetRandomWordIDs(_wordsPerHyperPlane); foreach (long id in wordIDs) plane.AddItem(id, Helpers.NextGaussian()); planes.Add(plane); Console.Write('.'); } return new LSHashFunction(planes); }
public SimpleStory() { Vector = new WordVector(); }
internal static HandleRef getCPtr(WordVector obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }
public Example(WordVector word, MorphoSyntacticContext context, double[] target ) { Input = new double[WordVector.VectorLength + MorphoSyntacticContext.VectorLength]; word.Elements.CopyTo(Input,0); context.Elements.CopyTo(Input, WordVector.VectorLength); ExpectedResult = target; }
public WordVector(WordVector orig) : this(modshogunPINVOKE.new_WordVector__SWIG_5(WordVector.getCPtr(orig)), true) { if (modshogunPINVOKE.SWIGPendingException.Pending) throw modshogunPINVOKE.SWIGPendingException.Retrieve(); }