Skip to content

Commit

Permalink
class label fixed + threshold type: manual
Browse files Browse the repository at this point in the history
  • Loading branch information
ksiminski committed May 10, 2024
1 parent 651de15 commit f9c14e6
Show file tree
Hide file tree
Showing 33 changed files with 1,032 additions and 285 deletions.
1 change: 0 additions & 1 deletion source/auxiliary/confusion-matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ double ksi::confusion_matrix::TestF1score (const ksi::result & r)
return (2.0 * recall * precision) / (recall + precision);
}


std::string ksi::confusion_matrix::ca(int n)
{
std::stringstream ss;
Expand Down
7 changes: 4 additions & 3 deletions source/auxiliary/roc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ std::string ksi::to_string (const ksi::roc_threshold & th)
case ksi::roc_threshold::mean : return "mean";
case ksi::roc_threshold::minimal_distance : return "minimal-distance";
case ksi::roc_threshold::youden : return "youden";
case ksi::roc_threshold::manual : return "manual";
case ksi::roc_threshold::none : return "none";
default : return "error";
}
}

double ksi::roc::trapezoidArea(double x1, double x2, double y1, double y2)
{
return abs(x1 - x2) * (y1 + y2) / 2;
return fabs(x1 - x2) * (y1 + y2) / 2;
}

ksi::results ksi::roc::calculate_ROC_points (std::vector<double> & Out,
Expand Down Expand Up @@ -69,7 +70,7 @@ ksi::results ksi::roc::calculate_ROC_points (std::vector<double> & Out,
iter != Out.end();
iter++)
{
if (abs(*iter - negativeClassvalue) < epsilon) // negative
if (fabs(*iter - negativeClassvalue) < epsilon) // negative
nNeg++;
else
nPos++;
Expand All @@ -96,7 +97,7 @@ ksi::results ksi::roc::calculate_ROC_points (std::vector<double> & Out,
points.push_back(punkt);


if (abs(iter->first - negativeClassvalue) < epsilon) // negative
if (fabs(iter->first - negativeClassvalue) < epsilon) // negative
{
nFP--;
//cerr << "n ";
Expand Down
1 change: 1 addition & 0 deletions source/auxiliary/roc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace ksi
mean, ///< mean value of positive and negative class labels
youden, ///< Youden criterion
minimal_distance, ///< minimal distance of ROC to point (0, 1)
manual, ///< the threshold value must be set manually
none ///< none
};

Expand Down
39 changes: 39 additions & 0 deletions source/neuro-fuzzy/abstract-annbfis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,45 @@ ksi::abstract_annbfis::abstract_annbfis(int nRules,
_minimal_typicality = dbMinimalTypicality;
}

ksi::abstract_annbfis::abstract_annbfis(int nRules, double dbFrobeniusEpsilon, int nTuningIterations, double dbLearningCoefficient, bool bNormalisation, const t_norm& tnorm, const implication& imp, const partitioner& Partitioner, double positive_class, double negative_class, double threshold_value, const double dbMinimalTypicality) : neuro_fuzzy_system()
{
_nRules = nRules;
_dbFrobeniusEpsilon = dbFrobeniusEpsilon;
_nTuningIterations = nTuningIterations;
_dbLearningCoefficient = dbLearningCoefficient;
_bNormalisation = bNormalisation;
if (not _pTnorm)
_pTnorm = tnorm.clone();
if (not _pPartitioner)
_pPartitioner = Partitioner.clone();
if (not _pImplication)
_pImplication = imp.clone();
_positive_class = positive_class;
_negative_class = negative_class;
_threshold_type = ksi::roc_threshold::manual;
_threshold_value = threshold_value;
_minimal_typicality = dbMinimalTypicality;
}

ksi::abstract_annbfis::abstract_annbfis(int nRules, int nClusteringIterations, int nTuningIterations, double dbLearningCoefficient, bool bNormalisation, const t_norm& tnorm, const implication& imp, const partitioner& Partitioner, double positive_class, double negative_class, double threshold_value, const double dbMinimalTypicality): neuro_fuzzy_system()
{
_nRules = nRules;
_nClusteringIterations = nClusteringIterations;
_nTuningIterations = nTuningIterations;
_dbLearningCoefficient = dbLearningCoefficient;
_bNormalisation = bNormalisation;
if (not _pTnorm)
_pTnorm = tnorm.clone();
if (not _pPartitioner)
_pPartitioner = Partitioner.clone();
if (not _pImplication)
_pImplication = imp.clone();
_positive_class = positive_class;
_negative_class = negative_class;
_threshold_type = ksi::roc_threshold::manual;
_threshold_value = threshold_value;
_minimal_typicality = dbMinimalTypicality;
}

ksi::partition ksi::abstract_annbfis::doPartition(const ksi::dataset& X)
{
Expand Down
40 changes: 36 additions & 4 deletions source/neuro-fuzzy/abstract-annbfis.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ namespace ksi
abstract_annbfis (int nRules, int nClusteringIterations, int nTuningIterations,
double dbLearningCoefficient, bool bNormalisation, const t_norm & tnorm, const implication & imp, const partitioner & Partitioner, double positive_class, double negative_class, ksi::roc_threshold threshold_type, const double dbMinimalTypicality = -1);

/** constructor
* @param nRules number of rules
* @param nClusteringIterations number of clustering iterations
* @param nTuningIterations number of tuning iterations
* @param dbLearningCoefficient learning coefficient for gradient method
* @param tnorm a t-norm
* @param imp implication
* @param Partitioner partition method object
* @param dbPositiveClass label of a positive class
* @param dbNegativeClass label of a negative class
* @param threshold_value classification threshold value
* @param dbMinimalTypicality minimal typicality for outliers
* @date 2024-05-09
*/
abstract_annbfis (int nRules, int nClusteringIterations, int nTuningIterations,
double dbLearningCoefficient, bool bNormalisation, const t_norm & tnorm, const implication & imp, const partitioner & Partitioner, double positive_class, double negative_class, double threshold_value, const double dbMinimalTypicality = -1);

/** constructor
* @param nRules number of rules
* @param dbFrobeniusEpsilon epsilon for Frobenius norm in clustering
Expand All @@ -94,6 +111,24 @@ namespace ksi
abstract_annbfis (int nRules, double dbFrobeniusEpsilon, int nTuningIterations,
double dbLearningCoefficient, bool bNormalisation, const t_norm & tnorm, const implication & imp, const partitioner & Partitioner, double positive_class, double negative_class, ksi::roc_threshold threshold_type, const double dbMinimalTypicality = -1);

/** constructor
* @param nRules number of rules
* @param dbFrobeniusEpsilon epsilon for Frobenius norm in clustering
* @param nTuningIterations number of tuning iterations
* @param dbLearningCoefficient learning coefficient for gradient method
* @param tnorm a t-norm
* @param imp implication
* @param Partitioner partition method object
* @param dbPositiveClass label of a positive class
* @param dbNegativeClass label of a negative class
* @param threshold_value classification threshold value
* @param dbMinimalTypicality minimal typicality for outliers
* @date 2024-05-09
*/
abstract_annbfis (int nRules, double dbFrobeniusEpsilon, int nTuningIterations,
double dbLearningCoefficient, bool bNormalisation, const t_norm & tnorm, const implication & imp, const partitioner & Partitioner, double positive_class, double negative_class, double threshold_value, const double dbMinimalTypicality = -1);



abstract_annbfis(const abstract_annbfis & a);
abstract_annbfis(abstract_annbfis && a);
Expand All @@ -109,9 +144,6 @@ namespace ksi
~abstract_annbfis();





public:
/** The method creates a fuzzy rulebase from the dataset.
* @param nClusteringIterations number of clustering iterations
Expand All @@ -126,7 +158,7 @@ namespace ksi
virtual void createFuzzyRulebase (
int nClusteringIterations, int nTuningIterations,
double dbLearningCoefficient,
const dataset & train, const dataset & validation);
const dataset & train, const dataset & validation) override;


public:
Expand Down
73 changes: 61 additions & 12 deletions source/neuro-fuzzy/abstract-ma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,63 @@ ksi::abstract_ma::abstract_ma(int nRules,
_minimal_typicality = dbMinimalTypicality;
}


ksi::abstract_ma::abstract_ma(int nRules,
double dbFrobeniusEpsilon,
int nTuningIterations,
double dbLearningCoefficient,
bool bNormalisation,
const ksi::t_norm & tnorm,
const ksi::partitioner & Partitioner,
double positive_class,
double negative_class,
const double threshold_value,
const double dbMinimalTypicality)
{
_nRules = nRules;
_dbFrobeniusEpsilon = dbFrobeniusEpsilon;
_nTuningIterations = nTuningIterations;
_dbLearningCoefficient = dbLearningCoefficient;
_bNormalisation = bNormalisation;
if (not _pTnorm)
_pTnorm = tnorm.clone();
if (not _pPartitioner)
_pPartitioner = Partitioner.clone();
_positive_class = positive_class;
_negative_class = negative_class;
_threshold_type = ksi::roc_threshold::manual;
_threshold_value = threshold_value;
_minimal_typicality = dbMinimalTypicality;
}


ksi::abstract_ma::abstract_ma(int nRules,
int nClusteringIterations,
int nTuningIterations,
double dbLearningCoefficient,
bool bNormalisation,
const ksi::t_norm & tnorm,
const partitioner & Partitioner,
double positive_class,
double negative_class,
ksi::roc_threshold threshold_type,
const double dbMinimalTypicality)
{
_nRules = nRules;
_nClusteringIterations = nClusteringIterations;
_nTuningIterations = nTuningIterations;
_dbLearningCoefficient = dbLearningCoefficient;
_bNormalisation = bNormalisation;
if (not _pTnorm)
_pTnorm = tnorm.clone();
if (not _pPartitioner)
_pPartitioner = Partitioner.clone();
_positive_class = positive_class;
_negative_class = negative_class;
_threshold_type = threshold_type;
_minimal_typicality = dbMinimalTypicality;
}

ksi::abstract_ma::abstract_ma(int nRules,
int nClusteringIterations,
int nTuningIterations,
Expand All @@ -305,17 +362,8 @@ ksi::abstract_ma::abstract_ma(int nRules,
const partitioner & Partitioner,
double positive_class,
double negative_class,
ksi::roc_threshold threshold_type,
const double dbMinimalTypicality)
/* : abstract_ma (nRules,
nClusteringIterations,
nTuningIterations,
dbLearningCoefficient,
bNormalisation,
tnorm,
Partitioner,
dbMinimalTypicality)
*/
const double threshold_value,
const double dbMinimalTypicality)
{
_nRules = nRules;
_nClusteringIterations = nClusteringIterations;
Expand All @@ -328,7 +376,8 @@ ksi::abstract_ma::abstract_ma(int nRules,
_pPartitioner = Partitioner.clone();
_positive_class = positive_class;
_negative_class = negative_class;
_threshold_type = threshold_type;
_threshold_type = ksi::roc_threshold::manual;
_threshold_value = threshold_value;
_minimal_typicality = dbMinimalTypicality;
}

Expand Down
33 changes: 33 additions & 0 deletions source/neuro-fuzzy/abstract-ma.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ namespace ksi
*/
abstract_ma (int nRules, int nClusteringIterations, int nTuningIterations,
double dbLearningCoefficient, bool bNormalisation, const t_norm & tnorm, const partitioner & Partitioner, double positive_class, double negative_class, ksi::roc_threshold threshold_type, const double dbMinimalTypicality = -1);

/** constructor
* @param nRules number of rules
* @param dbFrobeniusEpsilon epsilon for Frobeniu norm for the clustering algorithm
* @param nTuningIterations number of tuning iterations
* @param dbLearningCoefficient learning coefficient for gradient method
* @param tnorm a t-norm
* @param positive_class label for positive_class
* @param negative_class label for negative_class
* @param threshold_value threshold value for classification
* @param dbMinimalTypicality minimal typicality for outliers
*/
abstract_ma (int nRules, int nClusteringIterations, int nTuningIterations,
double dbLearningCoefficient, bool bNormalisation, const t_norm & tnorm, const partitioner & Partitioner, double positive_class, double negative_class, const double threshold_value, const double dbMinimalTypicality = -1);



/** constructor
Expand All @@ -74,6 +89,24 @@ namespace ksi
double positive_class, double negative_class, ksi::roc_threshold threshold_type, const double dbMinimalTypicality = -1
);

/** constructor
* @param nRules number of rules
* @param dbFrobeniusEpsilon epsilon for Frobeniu norm for the clustering algorithm
* @param nTuningIterations number of tuning iterations
* @param dbLearningCoefficient learning coefficient for gradient method
* @param tnorm a t-norm
* @param Partitioner clustering object
* @param positive_class label for positive_class
* @param negative_class label for negative_class
* @param threshold_value threshold value for classification
* @param dbMinimalTypicality minimal typicality for outliers
* @date 2024-05-09
*/
abstract_ma (int nRules, double dbFrobeniusEpsilon, int nTuningIterations,
double dbLearningCoefficient, bool bNormalisation, const t_norm & tnorm, const partitioner & Partitioner,
double positive_class, double negative_class, const double threshold_value, const double dbMinimalTypicality = -1
);


/** constructor
* @param nRules number of rules
Expand Down
57 changes: 57 additions & 0 deletions source/neuro-fuzzy/abstract-tsk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,63 @@ ksi::abstract_tsk::abstract_tsk(int nRules,
}


ksi::abstract_tsk::abstract_tsk(int nRules,
double dbFrobeniusEpsilon,
int nTuningIterations,
double dbLearningCoefficient,
bool bNormalisation,
const ksi::t_norm & tnorm,
const ksi::partitioner & Partitioner,
double positive_class,
double negative_class,
double threshold_value,
const double dbMinimalTypicality)
{
_nRules = nRules;
_dbFrobeniusEpsilon = dbFrobeniusEpsilon;
_nTuningIterations = nTuningIterations;
_dbLearningCoefficient = dbLearningCoefficient;
_bNormalisation = bNormalisation;
if (not _pTnorm)
_pTnorm = tnorm.clone();
if (not _pPartitioner)
_pPartitioner = Partitioner.clone();
_positive_class = positive_class;
_negative_class = negative_class;
_threshold_type = ksi::roc_threshold::manual;
_threshold_value = threshold_value;
_minimal_typicality = dbMinimalTypicality;
}

ksi::abstract_tsk::abstract_tsk(int nRules,
int nClusteringIterations,
int nTuningIterations,
double dbLearningCoefficient,
bool bNormalisation,
const ksi::t_norm & tnorm,
const ksi::partitioner & Partitioner,
double positive_class,
double negative_class,
double threshold_value,
const double dbMinimalTypicality)
{
_nRules = nRules;
_nClusteringIterations = nClusteringIterations;
_nTuningIterations = nTuningIterations;
_dbLearningCoefficient = dbLearningCoefficient;
_bNormalisation = bNormalisation;
if (not _pTnorm)
_pTnorm = tnorm.clone();
if (not _pPartitioner)
_pPartitioner = Partitioner.clone();
_positive_class = positive_class;
_negative_class = negative_class;
_threshold_type = ksi::roc_threshold::manual;
_threshold_value = threshold_value;
_minimal_typicality = dbMinimalTypicality;
}


ksi::abstract_tsk::~abstract_tsk()
{

Expand Down
Loading

0 comments on commit f9c14e6

Please sign in to comment.