public async Task <bool> RetreiveMetadataAsync() { Debug.WriteLine("Loading " + Title + "..."); try { var client = new HttpClient(); client.DefaultRequestHeaders.Add("range", "bytes=0-10"); var buffer = await client.GetBufferAsync(Uri); int?headerLength = ID3.GetID3v2HeaderLength(buffer.ToArray()); if (!headerLength.HasValue) { return(false); } client.DefaultRequestHeaders["range"] = "bytes=0-" + headerLength.Value; buffer = await client.GetBufferAsync(Uri); ID3.ExtractTagsFromBuffer(buffer, this); return(true); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); var dialog = new MessageDialog(Title + Environment.NewLine + ex.Message, "Erreur lors de l'extraction des métadonnées"); await dialog.ShowAsync(); } return(false); }
public Song(string file) { if (StringNetworkTools.IsURL(file)) { //Setup MP3 IDv1 TAG Reader //First we get our MP3TAG from remote file byte[] id3data = WebRequester.Request(file, null, null, 128); this._ID3 = new ID3(id3data); if (_ID3.hasTag) { this.mp3tag = _ID3; this.Name = $"{mp3tag.Artist} - {mp3tag.Title}"; } else { string href = StringNetworkTools.FileFromURL(file); this.Name = href.Split('.')[0]; } this.URL = file; } else { this.Name = file.Split('.')[0]; this.URL = file; this.mp3tag = null; } }
public static void Main(string[] args) { //Log.GainOn = true; //Log.InfoOn = true; //Log.NodeOn = true; Log.StatsOn = true; //Log.VerboseOn = true; double confidenceLevel = 0.95; string trainingSetPath = @"C:\coding\ml\test\training_subsetD.arff"; string testingSetPath = @"C:\coding\ml\test\testingD.arff"; if (args.Length >= 3) { confidenceLevel = Convert.ToDouble(args[0]); trainingSetPath = args[1]; testingSetPath = args[2]; } Console.WriteLine("confidenceLevel is {0}", confidenceLevel); Console.WriteLine("trainingSetPath is {0}", trainingSetPath); Console.WriteLine("testingSetPath is {0}", testingSetPath); ID3 id3 = new ID3(); ID3Node root = id3.Train(trainingSetPath, confidenceLevel); id3.Test(testingSetPath, root); }
private static void Tennis(double confidenceLevel) { ID3 id3 = new ID3(); ID3Node root = id3.Train(@"C:\coding\ml\test\tennis.arff", confidenceLevel); id3.Test(@"C:\coding\ml\test\tennis.arff", root); }
private static void Full(double confidenceLevel) { ID3 id3 = new ID3(); ID3Node root = id3.Train(@"C:\coding\ml\test\training_subsetD.arff", confidenceLevel); id3.Test(@"C:\coding\ml\test\testingD.arff", root); }
public void Train(Instances instances, int numberOfModels, int?randomSeed = null, int maxDepth = 0) { // First train and test without bagging this.NonBaggingModel = new ID3(); this.NonBaggingModel.Train(instances, Bagging.ConfidenceLevel, maxDepth); this.Models = new List <ID3>(); // Do sampling with replacement and then train the model Random random = randomSeed == null ? new Random() : new Random((int)randomSeed); for (int i = 0; i < numberOfModels; i++) { Instances newInstances = new Instances(instances, 0); for (int j = 0; j < instances.numInstances(); j++) { int randomSample = random.Next(0, instances.numInstances() - 1); newInstances.add(instances.instance(randomSample)); } ID3 model = new ID3(); model.Train(newInstances, Bagging.ConfidenceLevel, maxDepth); this.Models.Add(model); } }
private async void RetreiveMetadataALTERNATIVE() { try { var client = new HttpClient(); client.DefaultRequestHeaders.Add("range", "bytes=0-10"); var buffer = await client.GetBufferAsync(Uri); int?headerLength = ID3.GetID3v2HeaderLength(buffer.ToArray()); if (!headerLength.HasValue) { return; } Debug.WriteLine("Header length = " + headerLength.Value); client.DefaultRequestHeaders["range"] = "bytes=0-" + headerLength.Value; buffer = await client.GetBufferAsync(Uri); using (var stream = new MemoryStream(buffer.ToArray())) { var bytes = buffer.ToArray(); var tagFile = TagLib.File.Create(new StreamFileAbstraction(name, stream, stream)); var id3 = tagFile.GetTag(TagTypes.Id3v2); Title = id3.Title; if (id3.FirstPerformer != null) { Artist = id3.FirstPerformer; } if (id3.Album != null) { Album = id3.Album; } Cover = await id3.Pictures[0].Data.Data.ToBitmapImage(); // Save cover //StorageFolder storageFolder = ApplicationData.Current.LocalFolder; //StorageFile storageFile = await storageFolder.CreateFileAsync("test_cover.jpg", CreationCollisionOption.ReplaceExisting); //await FileIO.WriteBytesAsync(storageFile, id3.Pictures[0].Data.Data); //var coverUri = new Uri(storageFile.Path); //Debug.WriteLine(coverUri); int bitrate = tagFile.Properties.AudioBitrate * 125; Duration = TimeSpan.FromSeconds(size / bitrate); } MetadataRetreived?.Invoke(); } catch (Exception e) { Debug.WriteLine(e.Message); var dialog = new MessageDialog(Title + Environment.NewLine + e.Message, "Erreur lors de l'extraction des métadonnées"); await dialog.ShowAsync(); } }
static void Main(string[] args) { byte[] test = WebRequester.Request("http://tv2.partizan.si/YoutubeVideoPlayer/api/audio/song2.mp3", null, null, 128); ID3 tag = new ID3(test); Console.WriteLine("Tag is available: " + tag.hasTag); Console.WriteLine("Artist: " + tag.Artist); Console.WriteLine("Title: " + tag.Title); Console.ReadLine(); }
public static void RunID3() { List <DDataRecord> X = LoadSample(); //As ID3 does not support continuous value, must do manually conversion foreach (DDataRecord rec in X) { int temperature = int.Parse(rec["temperature"]); int humidity = int.Parse(rec["humidity"]); if (temperature < 75) { rec["temperature"] = "< 75"; } else { rec["temperature"] = ">= 75"; } if (humidity < 80) { rec["humidity"] = "< 80"; } else { rec["humidity"] = ">= 80"; } } ID3 <DDataRecord> algorithm = new ID3 <DDataRecord>(); algorithm.Train(X); //algorithm.ErrorReducePrune(Xval); //error reduce prune using cross valiation set Console.WriteLine("ID3 Tree Built!"); for (int i = 0; i < X.Count; i++) { DDataRecord rec = X[i]; Console.WriteLine("rec: "); string[] feature_names = rec.FindFeatures(); foreach (string feature_name in feature_names) { Console.WriteLine(feature_name + " = " + rec[feature_name]); } Console.WriteLine("Label: " + rec.Label); Console.WriteLine("Predicted Label: " + algorithm.Predict(X[i])); Console.WriteLine(); } algorithm.WriteToXml("ID3.xml"); }
private void butTree_Click(object sender, EventArgs e) { id3 = new ID3(PATH); id3.Show(); }
static void Main(string[] args) { Console.WriteLine("Start.... " + DateTime.Now); FileStream fs = new FileStream("train.txt", FileMode.Open); StreamReader rd = new StreamReader(fs, Encoding.UTF8); string line; string class1 = "Yes"; string class2 = "No"; List <string> attribute = new List <string>(); line = rd.ReadLine(); attribute = line.Split(',').ToList(); List <int> remainingAttribute = new List <int>(); for (int i = 0; i < attribute.Count; i++) { remainingAttribute.Add(i); } List <value> listData = new List <value>(); int c1 = 0; int c2 = 0; while ((line = rd.ReadLine()) != null) { List <string> item = new List <string>(); item = line.Split(',').ToList(); if (item[item.Count - 1] == class1) { c1++; } else { c2++; } value value = new value(); value.values = item; listData.Add(value); } //foreach (var i in listData) //{ // Console.WriteLine(i.toString()); //} //Console.WriteLine("C1=" + c1 + " C2=" + c2); //entropy entropy = new entropy(); //Node node= entropy.tinhEntropy(c1, c2, remainingAttribute, listData, class1, class2); //List<int> newremain = remainingAttribute.FindAll(x => x != node.attr).ToList(); //foreach (var i in newremain) Console.WriteLine(i); //foreach(var i in node.children) //{ // Console.WriteLine(i.value + " c1 " +i.nClass1 + " c2 " + i.nClass2); // if(i.isLeaf) // { // } // else // { // Node nodec = entropy.tinhEntropy(i.nClass1, i.nClass2, newremain, i.data, class1, class2); // } //} rd.Close(); DateTime trainStart = DateTime.Now; Console.WriteLine("Training...." + trainStart); ID3 iD = new ID3(attribute, remainingAttribute, listData, class1, class2, c1, c2); iD.start(); DateTime trainEnd = DateTime.Now; Console.WriteLine("End training...." + trainEnd); Console.WriteLine("time training...." + (trainEnd - trainStart).ToString() + " Tong du lieu traning: " + listData.Count); Console.WriteLine("Print...." + DateTime.Now); Node no = new Node(); //Console.WriteLine(no.isLeaf); iD.printTree(); //value value2 = new value(); //List<string> newlist = new List<string>(); //newlist.Add("black"); //newlist.Add("number"); //newlist.Add("yamaha"); //newlist.Add("blade"); //newlist.Add("conanhoa"); //value2.values = newlist; //string s=iD.Ktra(value2); //string d=value2.toString(); //Console.WriteLine( d); //Console.WriteLine("kq " + s); FileStream fstest = new FileStream("test.txt", FileMode.Open); StreamReader rdtest = new StreamReader(fstest, Encoding.UTF8); List <value> listDataTest = new List <value>(); while ((line = rdtest.ReadLine()) != null) { List <string> item = new List <string>(); item = line.Split(',').ToList(); value value = new value(); value.values = item; listDataTest.Add(value); } foreach (var i in listDataTest) { Console.WriteLine(i.toString() + " --> " + iD.Ktra(i)); } rdtest.Close(); Console.ReadLine(); }
static void MenuSelection(string selection) { switch (selection) { case "1": { var problem = new ID1(); problem.Start(); break; } case "2": { var problem = new ID2(); problem.Start(); break; } case "3": { var problem = new ID3(); problem.Start(); break; } case "4": { var problem = new ID4(); problem.Start(); break; } case "5": { var problem = new ID5(); problem.Start(); break; } case "6": { var problem = new ID6(); problem.Start(); break; } case "7": { var problem = new ID7(); problem.Start(); break; } case "8": { var problem = new ID8(); problem.Start(); break; } case "9": { var problem = new ID9(); problem.Start(); break; } case "10": { var problem = new ID10(); problem.Start(); break; } case "11": { var problem = new ID11(); problem.Start(); break; } case "12": { var problem = new ID12(); problem.Start(); break; } case "13": { var problem = new ID13(); problem.Start(); break; } case "14": { var problem = new ID14(); problem.Start(); break; } case "266": { var problem = new ID266(); problem.Start(); break; } default: break; } }