Revize 76072df0
Přidáno uživatelem Roman Kalivoda před téměř 4 roky(ů)
Server/ServerApp/Predictor/PredictionController.cs | ||
---|---|---|
93 | 93 |
this.FeatureExtractor = new FeatureExtractor(this.DataParser, this.Configuration); |
94 | 94 |
|
95 | 95 |
DirectoryInfo di = new DirectoryInfo(Configuration.ModelDataPath); |
96 |
_log.Debug($"Looking for directory: {Configuration.ModelDataPath}"); |
|
97 |
if (! di.Exists) |
|
98 |
{ |
|
99 |
_log.Info($"Creating the model data directory: {Configuration.ModelDataPath}"); |
|
100 |
di.Create(); |
|
101 |
} |
|
96 | 102 |
FileInfo[] files = di.GetFiles(); |
97 |
if (Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Any())
|
|
103 |
if (Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Count() == Configuration.PredictorCount)
|
|
98 | 104 |
{ |
99 | 105 |
_log.Info("Found existing predictors, loading the newest."); |
100 |
this.Load(Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Last().Select(f => f.Name.Split("_".ToCharArray())[0]).First()); |
|
106 |
var predictorID = Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Last().Select(f => f.Name.Split("_".ToCharArray())[0]).First(); |
|
107 |
this.Load(predictorID); |
|
101 | 108 |
} |
102 | 109 |
else |
103 | 110 |
{ |
104 | 111 |
_log.Info("No predictors found, creating new ones"); |
105 | 112 |
for (int i = 0; i < this.Configuration.PredictorCount; i++) |
106 | 113 |
{ |
107 |
predictors[i] = new NaiveBayesClassifier(); |
|
114 |
predictors[i] = new SdcaMaximumEntropyClassifier(); |
|
115 |
} |
|
116 |
lock (predictorsLock) |
|
117 |
{ |
|
118 |
this.Predictors = predictors; |
|
108 | 119 |
} |
109 | 120 |
} |
110 |
lock (predictorsLock) |
|
111 |
{ |
|
112 |
this.Predictors = predictors; |
|
113 |
} |
|
121 |
|
|
114 | 122 |
PredictorConfiguration.SaveConfig(PredictorConfiguration.DEFAULT_CONFIG_PATH, Configuration); |
115 | 123 |
} |
116 | 124 |
public List<string> GetPredictors() |
... | ... | |
120 | 128 |
|
121 | 129 |
public int Load(string predictorID) |
122 | 130 |
{ |
123 |
DirectoryInfo di = new DirectoryInfo(Configuration.ModelDataPath); |
|
131 |
DirectoryInfo di = new DirectoryInfo(Configuration.ModelDataPath); |
|
132 |
if (!di.Exists) |
|
133 |
{ |
|
134 |
_log.Warn("The model data directory could not be found."); |
|
135 |
return 2; |
|
136 |
} |
|
124 | 137 |
FileInfo[] files = di.GetFiles($"{predictorID}_*.zip"); |
125 | 138 |
if (Array.FindAll(files, f => Regex.IsMatch(f.Name, $@"{predictorID}_\d+.zip")).Any()){ |
126 | 139 |
IPredictor[] newPredictors = new IPredictor[this.Configuration.PredictorCount]; |
... | ... | |
128 | 141 |
{ |
129 | 142 |
for (int i = 0; i < this.Configuration.PredictorCount; i++) |
130 | 143 |
{ |
131 |
newPredictors[i] = new NaiveBayesClassifier(Array.Find(files, f => Regex.IsMatch(f.Name, $"{predictorID}_{i}.zip")).FullName);
|
|
144 |
newPredictors[i] = new SdcaMaximumEntropyClassifier(Array.Find(files, f => Regex.IsMatch(f.Name, $"{predictorID}_{i}.zip")).FullName);
|
|
132 | 145 |
} |
133 | 146 |
files = di.GetFiles($"{predictorID}.txt"); |
134 | 147 |
var dataFilenames = File.ReadLines(files[0].FullName); |
... | ... | |
154 | 167 |
public void Save() |
155 | 168 |
{ |
156 | 169 |
DirectoryInfo di = new DirectoryInfo(Configuration.ModelDataPath); |
170 |
if (!di.Exists) |
|
171 |
{ |
|
172 |
_log.Warn("The model data directory could not be found."); |
|
173 |
return; |
|
174 |
} |
|
157 | 175 |
|
158 | 176 |
lock (predictorsLock) |
159 | 177 |
{ |
... | ... | |
168 | 186 |
public int Rollback() |
169 | 187 |
{ |
170 | 188 |
DirectoryInfo di = new DirectoryInfo(Configuration.ModelDataPath); |
189 |
if (!di.Exists) |
|
190 |
{ |
|
191 |
_log.Warn("The model data directory could not be found."); |
|
192 |
return 2; |
|
193 |
} |
|
171 | 194 |
FileInfo[] files = di.GetFiles(); |
172 |
if (Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Any())
|
|
195 |
if (Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Count() == Configuration.PredictorCount)
|
|
173 | 196 |
{ |
174 | 197 |
string RollbackedPredictorID = Array.FindAll(files, f => Regex.IsMatch(f.Name, @"[-]?\d+_\d+.zip")).GroupBy(f => f.Name.Split("_.".ToCharArray())[0]).OrderBy(f => DateTime.FromBinary(Convert.ToInt64(f.Key))).Last().Select(f => f.Name.Split("_".ToCharArray())[0]).First(); |
175 | 198 |
this.Delete(this.PredictorID); |
... | ... | |
184 | 207 |
private void Delete(string predictorID) |
185 | 208 |
{ |
186 | 209 |
DirectoryInfo di = new DirectoryInfo(Configuration.ModelDataPath); |
210 |
if (!di.Exists) |
|
211 |
{ |
|
212 |
_log.Warn("The model data directory could not be found."); |
|
213 |
return; |
|
214 |
} |
|
187 | 215 |
|
188 | 216 |
for (int i = 0; i < this.Configuration.PredictorCount; i++) |
189 | 217 |
{ |
Také k dispozici: Unified diff
Re #8597 Implementation of AbstractClassificationPredictor, SdcaMEClassifier