public MetricSimilarity(MelodySequence seq, IMetric metric, SimilarityType type = SimilarityType.Cosine) { this.metrics = new IMetric[]{metric}; this.target = seq.ToArray(); this.type = type; this.target_metrics = new Dictionary<Pair, float>[] { this.metrics[0].Generate(this.target) }; }
public MetricSimilarity(MelodySequence seq, IMetric[] metrics, SimilarityType type = SimilarityType.Cosine) { this.metrics = metrics; this.target = seq.ToArray(); target_metrics = new Dictionary<Pair, float>[metrics.Length]; this.type = type; for (int i = 0; i < metrics.Length; i++) target_metrics[i] = this.metrics[i].Generate(this.target); }
private void calculateButton_Click(object sender, EventArgs e) { string[] items = new string[fileListBox.Items.Count]; for (int i = 0; i < items.Length; i++) { items[i] = fileListBox.Items[i].ToString(); } SimilarityType type = SimilarityType.Euclidean; Enum.TryParse <SimilarityType>(similarityTypeComboBox.SelectedValue.ToString(), out type); resultTextBox.Text = Ensemble.Similarity(type, items).ToString("0.00000"); }
public static MetricSimilarity GenerateMetricSimilarityMulti(IEnumerable<Composition> comps, IMetric[] metrics, SimilarityType type = SimilarityType.Cosine) { List<Note> notes = new List<Note>(); foreach(var comp in comps) { if (comp.Tracks.Count < 1) continue; var seq = comp.Tracks[0].GetMainSequence() as MelodySequence; foreach (var n in seq.Notes) notes.Add(n); } return new MetricSimilarity(new MelodySequence(notes), metrics, type); }
public static string GetSimilarityTypeDescription(this SimilarityType methodType) { // get the field var field = methodType.GetType().GetField(methodType.ToString()); var customAttributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false); if (customAttributes.Count() > 0) { return((customAttributes.ElementAt(0) as DescriptionAttribute).Description); } else { return(methodType.ToString()); } }
public void ShowModelInfo() { Logger.WriteLine($"Encoder embedding dim: '{EncoderEmbeddingDim}'"); Logger.WriteLine($"Decoder embedding dim: '{DecoderEmbeddingDim}'"); Logger.WriteLine($"Encoder layer depth: '{EncoderLayerDepth}'"); Logger.WriteLine($"Decoder layer depth: '{DecoderLayerDepth}'"); Logger.WriteLine($"Encoder type: '{EncoderType}'"); Logger.WriteLine($"Decoder type: '{DecoderType}'"); Logger.WriteLine($"Hidden layer dim: '{HiddenDim}'"); Logger.WriteLine($"Enable segment embeddings: '{EnableSegmentEmbeddings}'"); Logger.WriteLine($"Enable shared embeddings: '{SharedEmbeddings}'"); Logger.WriteLine($"Enable tag embeddings: '{EnableTagEmbeddings}'"); Logger.WriteLine($"Multi-head size: '{MultiHeadNum}'"); Logger.WriteLine($"Pointer Generator: '{PointerGenerator}'"); if (!SimilarityType.IsNullOrEmpty()) { Logger.WriteLine($"Similarity Type: '{SimilarityType}'"); } if (SrcVocab != null) { Logger.WriteLine($"Source vocabulary size: '{SrcVocab.Count}'"); } if (TgtVocab != null) { Logger.WriteLine($"Target vocabulary size: '{TgtVocab.Count}'"); } if (ClsVocabs != null) { Logger.WriteLine($"The number of CLS vocabularies: '{ClsVocabs.Count}' "); for (int i = 0; i < ClsVocabs.Count; i++) { Logger.WriteLine($"CLS vocabulary {i} size: {ClsVocabs[ i ].Count}"); } } }
public static double Similarity(SimilarityType type, params string[] files) { REngine.SetEnvironmentVariables(); // There are several options to initialize the engine, but by default the following suffice: REngine engine = REngine.GetInstance(); engine.Evaluate("library(clue)"); string ensemble_statement = "ensemble = cl_ensemble("; for (int i = 0; i < files.Length; i++) { string statement = string.Empty; statement += $"array = read.csv(\"{files[i].Replace("\\", "\\\\")}\", header = FALSE)$V1\r\n"; statement += "if(is.na(array[1])){"; statement += $" P{i} = as.cl_partition(read.csv(\"{files[i].Replace("\\", "\\\\")}\", header = TRUE)$V1)"; statement += "}else{"; statement += $" P{i} = as.cl_partition(array)"; statement += "}"; engine.Evaluate(statement); ensemble_statement += $"P{i},"; } ensemble_statement = ensemble_statement.TrimEnd(new char[] { ',' }) + ")"; engine.Evaluate(ensemble_statement); engine.Evaluate("ag=cl_agreement(ensemble)"); var ag = engine.Evaluate("ag"); Console.WriteLine(ag.ToString()); var mean = engine.Evaluate($"mean(cl_agreement(ensemble, method = \"{type}\"))").AsVector(); double result = (double)mean[0]; // you should always dispose of the REngine properly. // After disposing of the engine, you cannot reinitialize nor reuse it //engine.Dispose(); return(result); }
private async Task <List <TrademarkDto> > ParseServerResponse(string response, SimilarityType type) { var tradeMarkCollection = new List <TrademarkDto>(); if (!string.IsNullOrEmpty(response)) { var results = JsonConvert.DeserializeObject <dynamic>(response); foreach (var result in results.results) { int.TryParse(result.barcode.ToString(), out int supervisorBarcode); var protDoc = _executor.GetQuery <GetProtectionDocsByBarcodeQuery>() .Process(q => q.Execute(supervisorBarcode)); if (protDoc != null) { var tdmDet = _mapper.Map <TrademarkDto>(protDoc); switch (type) { case SimilarityType.Image: tdmDet.ImageSimilarity = result.similarity; break; case SimilarityType.Phonetic: tdmDet.PhonSimilarity = result.similarity; break; case SimilarityType.Semantic: tdmDet.SemSimilarity = result.similarity; break; } byte[] responseImage = protDoc.Image; tdmDet.PreviewImage = responseImage != null ? $"data:image/png;base64,{Convert.ToBase64String(responseImage)}" : null; tradeMarkCollection.Add(tdmDet); } } } return(tradeMarkCollection); }