Skip to content

Commit 58b252b

Browse files
author
Timur Gilmullin
committed
#13: Examples of using --show-expected key added.
1 parent 459265e commit 58b252b

1 file changed

Lines changed: 69 additions & 40 deletions

File tree

README.md

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ FuzzyClassificator
3333

3434

3535
<a name="Chapter_1"></a>Introduction
36-
--------------
36+
------------------------------------
3737

3838
This program uses neural networks to solve classification problems, and uses fuzzy sets and fuzzy logic to interpreting results. FuzzyClassificator provided under the MIT License.
3939

4040
How does it work? Let see process scheme below.
4141

4242
![Two Stage of Classification Process](classification_process.png "Two Stage of Classification Process")
4343

44+
4445
<a name="Chapter_2"></a>How to use
45-
--------------
46+
----------------------------------
4647

4748
FuzzyClassificator uses ethalons.dat (default) as learning data and candidates.dat (default) for classifying data (See "Preparing data" chapter).
4849
Work contains two steps:
@@ -121,13 +122,18 @@ In all examples below, we used an Anaconda Python interpreter when you saw keywo
121122
--no-fuzzy
122123
Add key if You doesn't want show fuzzy results, only real. Not set by default.
123124

125+
--show-expected
126+
Show expected results in Classify mode.
127+
WARNING! Use only if your dat-file contains columns with expected results!
128+
124129
--reload
125130
Add key if You want reload network from file before usage. Not set by default.
126131

127132
-u [epochs], --update=[epochs]
128133
Update error status after this epochs time, 5 by default.
129134
This parameter affected training speed.
130135

136+
131137
<a name="Chapter_2_2_2"></a>***Work modes***
132138

133139
Learning Mode:
@@ -169,6 +175,7 @@ Classifying Mode:
169175
and outputs is number of neurons in output layer
170176
}
171177

178+
172179
<a name="Chapter_2_2_3"></a>***Usage examples***
173180

174181
Start learning with user's ethalon data file and neuronet options Config=(3,[3,2],2), 10 epochs, 0.1 learning rate and 0.05 momentum, epsilon is 0.01 and stop learning if errors less than 5%, update information in log every 5 epochs:
@@ -183,7 +190,8 @@ Where 'python' is full path to Pyzo Python 3.3.2 interpreter.
183190

184191

185192
<a name="Chapter_3"></a>Preparing data
186-
--------------
193+
--------------------------------------
194+
187195

188196
<a name="Chapter_3_1"></a>**ethalons.dat**
189197

@@ -234,21 +242,21 @@ This is default file with data set for classifying. This file contains tab-delim
234242

235243

236244
<a name="Chapter_4"></a>Report of classificating
237-
--------------
245+
------------------------------------------------
238246

239247
To classify each of input vectors You must to use --classify key. All columns are used as values of input vectors.
240248

241-
If You train Neuronet with command:
249+
If you trained Neuronet with command:
242250

243251
python FuzzyClassificator.py --ethalons ethalons.dat --learn config=3,3,2,2 epochs=1000 rate=0.1 momentum=0.05
244252

245-
And then classificate candidates vectors with command:
253+
And then you classificated candidates vectors with command:
246254

247255
python FuzzyClassificator.py --candidates candidates.dat --network network.xml --report report.txt --classify config=3,3,2,2
248256

249-
Then You'll get *report.text* file with information that looks like this:
257+
Then you will get the *report.text* file with information that looks like this:
250258

251-
Neuronet: C:\work\projects\FuzzyClassificator\network.xml
259+
Neuronet: x:\work\projects\FuzzyClassificator_dohq\network.xml
252260

253261
FuzzyScale = {Min, Low, Med, High, Max}
254262
Min = <Hyperbolic(x, {'a': 8, 'c': 0, 'b': 20}), [0.0, 0.23]>
@@ -269,7 +277,8 @@ Then You'll get *report.text* file with information that looks like this:
269277

270278

271279
<a name="Chapter_5"></a>Work with API
272-
--------------
280+
-------------------------------------
281+
273282

274283
<a name="Chapter_5_1"></a>**FuzzyClassificator.py**
275284

@@ -302,6 +311,7 @@ The *ClassifyingMode()* method only runs calculations using the trained neural n
302311

303312
Some examples are below.
304313

314+
305315
<a name="Chapter_5_1_1"></a>***API example to run Learning mode***
306316

307317
When you run Learning mode in CLI, for example:
@@ -312,10 +322,10 @@ Also you can run the same Learning mode command using API:
312322

313323
import FuzzyClassificator as FC
314324
import FCLogger
315-
325+
316326
FCLogger.SetLevel("info")
317327
FC.epochsToUpdate = 1
318-
328+
319329
parameters = {
320330
"config": "3,3,2,2",
321331
"epochs": 100,
@@ -324,9 +334,10 @@ Also you can run the same Learning mode command using API:
324334
"epsilon": 0.75,
325335
"stop": 1
326336
}
327-
337+
328338
FC.Main(learnParameters=parameters) # Learning mode
329-
339+
340+
330341
<a name="Chapter_5_1_2"></a>***API example to run Classifying mode***
331342

332343
When you run Classifying mode in CLI, for example:
@@ -337,76 +348,89 @@ Also you can run the same Classifying mode command using API:
337348

338349
import FuzzyClassificator as FC
339350
from FCLogger import SetLevel
340-
351+
341352
FC.candidatesDataFile = "candidates.dat"
342353
FC.neuroNetworkFile = "network.xml"
343354
FC.reportDataFile = "report.txt"
344355
FC.sepSymbol = "TAB"
345356
SetLevel("DEBUG")
346-
357+
347358
parameters = {
348359
"config": "3,3,2,2",
349360
}
350-
361+
351362
FC.Main(classifyParameters=parameters) # Classifying mode
352363

364+
353365
<a name="Chapter_5_1_3"></a>***Another API parameters***
354366

355-
import FuzzyClassificator as FC # Import main classificator's module
356-
367+
import FuzzyClassificator as FC # Import main classificator's module.
368+
357369
# Start learning or classificating mode with parameters.
358370
# If parameters are not defined then CLI-parameters are used.
359371
FC.Main(learnParameters=None, classifyParameters=None)
360-
372+
361373
FC.__version__ # Version of current FuzzyClassificator build.
362-
374+
363375
FC.ethalonsDataFile # File with ethalon data samples, 'ethalons.dat' by default.
364-
376+
365377
FC.candidatesDataFile # File with candidates data samples, 'candidates.dat' by default.
366-
378+
367379
FC.neuroNetworkFile # File with Neuro Network configuration, 'network.xml' by default.
368-
380+
369381
FC.reportDataFile # Report file with classification analysis, 'report.txt' by default.
370-
382+
371383
FC.bestNetworkFile # Where best network saved, 'best_nn.xml' by default.
372-
384+
373385
FC.bestNetworkInfoFile # Where information about best network saved, 'best_nn.txt' by default.
374-
386+
375387
FC.epochsToUpdate # Epochs between error status updated, 5 by default.
376-
388+
377389
FC.ignoreColumns # List of ignored columns. Empty list [] by default, e.g. FC.ignoreColumns = [1, 3].
378-
390+
379391
FC.ignoreRows # List of ignored rows. [1] by default, e.g. FC.ignoreRows = [1, 3].
380-
392+
381393
FC.sepSymbol # Separator symbol. TAB symbol '\t' used by default.
382-
394+
383395
FC.reloadNetworkFromFile # Reload or not Neuro Network from file before usage. False by default.
384-
396+
385397
FC.noFuzzyOutput # Show results with fuzzy values too if False (default). Show only real values in report if True.
386398

399+
FC.showExpected # Show expected results in Classify mode. WARNING! Use only if your dat-file contains columns with expected results to avoid errors!
400+
401+
387402
<a name="Chapter_5_2"></a>**PyBrainLearning.py**
388403

389404
This is library for work with fuzzy neural networks. You can import and re-use module in your programm if you'd like to realize own work with networks.
390405

391406
All routines to work with fuzzy neural networks realized in *FuzzyNeuroNetwork()* class. It contains next main methods:
392407

393-
- *ParseRawDataFile()* - used for parsing file with text raw data,
394-
- *PrepareDataSet()* - used for converting parsed raw-data into PyBrain dataset format,
395-
- *CreateNetwork()* - used for creating PyBrain network,
396-
- *CreateTrainer()* - used for creating PyBrain trainer,
397-
- *SaveNetwork()* - used for saving network in PyBrain xml-format,
398-
- *LoadNetwork()* - used for loading network from PyBrain xml-format file,
399-
- *Train()* - realize network training mechanism,
400-
- *CreateReport()* - creates text report after classification vector-candidates.
408+
import PyBrainLearning as FL # Import supporting module.
409+
410+
FL.ParseRawDataFile() # Used for parsing file with text raw data.
411+
412+
FL.PrepareDataSet() # Used for converting parsed raw-data into PyBrain dataset format.
413+
414+
FL.CreateNetwork() # Used for creating PyBrain network.
415+
416+
FL.CreateTrainer() # Used for creating PyBrain trainer.
417+
418+
FL.SaveNetwork() # Used for saving network in PyBrain xml-format.
419+
420+
FL.LoadNetwork() # Used for loading network from PyBrain xml-format file.
421+
422+
FL.Train() # Realize network training mechanism.
423+
424+
FL.CreateReport() # Create text report after classification vector-candidates.
401425

402-
You can import this class and use its methods in other projects.
403426

404427
<a name="Chapter_5_3"></a>**FuzzyRoutines.py**
405428

406429
Library contains some routines for work with fuzzy logic operators, fuzzy datasets and fuzzy scales.
407430

408431
There are some examples of working with fuzzy library after importing it. Just copying at the end of FuzzyRoutines and run it.
409432

433+
410434
<a name="Chapter_5_3_1"></a>***Work with membership functions***
411435

412436
Usage of some membership functions (uncomment one of them):
@@ -444,6 +468,7 @@ Calculating some function's values in [0, 1]:
444468
res = funct.mju(xPar) # calculate one value of MF with given parameters
445469
print('{}({:1.1f}, {}) = {:1.4f}'.format(funct.name, xPar, funct.parameters, res))
446470

471+
447472
<a name="Chapter_5_3_2"></a>***Work with fuzzy set***
448473

449474
fuzzySet = FuzzySet(funct, (0., 1.)) # creating fuzzy set A = <mju_funct, support_set>
@@ -464,6 +489,7 @@ Calculating some function's values in [0, 1]:
464489
print('New value of Defuz({}) = {:1.2f}'.format(fuzzySet.name, fuzzySet.Defuz()))
465490
print('Printing fuzzy set after changes:', fuzzySet)
466491

492+
467493
<a name="Chapter_5_3_3"></a>***Work with fuzzy scales***
468494

469495
Fuzzy scale is an ordered set of linguistic variables that looks like this:
@@ -509,6 +535,7 @@ Change scale levels:
509535
for item in scale.levels:
510536
print('Defuz({}) = {:1.2f}'.format(item['name'], item['fSet'].Defuz()))
511537

538+
512539
<a name="Chapter_5_3_4"></a>***Work with Universal Fuzzy Scale***
513540

514541
Universal fuzzy scales S_f = {Min, Low, Med, High, Max} pre-defined in UniversalFuzzyScale() class.
@@ -564,6 +591,7 @@ Finding fuzzy level using GetLevelByName() function without exact matching:
564591
res = uniFScale.GetLevelByName('Highest', exactMatching=False)
565592
print("GetLevelByName('Highest', {}) = {}, {}".format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))
566593

594+
567595
<a name="Chapter_5_3_5"></a>***Work with fuzzy logic operators***
568596

569597
Checks that number is in [0, 1]:
@@ -614,6 +642,7 @@ Calculates result of S-coNorm operations for N numbers, N > 2:
614642
print("SCoNormCompose(0.25, 0.5, 0.75, 'boundary') =", SCoNormCompose(0.25, 0.5, 0.75, normType='boundary'))
615643
print("SCoNormCompose(0.25, 0.5, 0.75, 'drastic') =", SCoNormCompose(0.25, 0.5, 0.75, normType='drastic'))
616644

645+
617646
<a name="Chapter_5_3_6"></a>***Output examples***
618647

619648
If you run code above - you'll see next console output:

0 commit comments

Comments
 (0)