# Path: core/kover/learning/common/models.py
# class BaseModel(object):
# class CARTModel(BaseModel):
# class SCMModel(BaseModel):
# class ConjunctionModel(SCMModel):
# class DisjunctionModel(SCMModel):
#     def __init__(self):
#     def predict(self, X):
# 	def predict_proba(self, X):
#     def learner(self):
#     def __str__(self):
#     def __init__(self, class_tags=None):
#     def predict(self, X):
#     def predict_proba(self, X):
#     def learner(self):
#     def _to_string(self, node=None,depth=0):
#     def __len__(self):
#     def depth(self):
#     def __init__(self):
#     def add(self, rule):
#     def predict(self, X):
#     def predict_proba(self, X):
#     def remove(self, index):
#     def example_dependencies(self):
#     def learner(self):
#     def type(self):
#     def _to_string(self, separator=" "):
#     def __eq__(self, other):
#     def __iter__(self):
#     def __len__(self):
#     def predict_proba(self, X):
#     def type(self):
#     def __str__(self):
#     def predict_proba(self, X):
#     def type(self):
#     def __str__(self):
# 
# Path: core/kover/utils.py
# def _class_to_string(instance):
#     """
#     Returns a string representation of the public attributes of a class.
#     
#     Parameters:
#     -----------
#     instance: object
#         An instance of any class.
#         
#     Returns:
#     --------
#     string_rep: string
#         A string representation of the class and its public attributes.
#         
#     Notes:
#     -----
#     Private attributes must be marked with a leading underscore.
#     """
#     return instance.__class__.__name__ + "(" + ",".join(
#         [str(k) + "=" + str(v) for k, v in instance.__dict__.iteritems() if str(k[0]) != "_"]) + ")"


import logging
import numpy as np
from math import ceil
from ..common.models import scm, conjunction, ConjunctionModel, disjunction, DisjunctionModel
from ...utils import _class_to_string
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""





UTIL_BLOCK_SIZE = 1000000


def _compute_rule_importances(rule_classifications, model_rules_idx, training_example_idx):
    model_rule_classifications = rule_classifications.get_columns(model_rules_idx)[training_example_idx]
    model_neg_prediction_idx = np.where(np.prod(model_rule_classifications, axis=1) == 0)[0]
    return (float(len(model_neg_prediction_idx)) - model_rule_classifications[model_neg_prediction_idx].sum(axis=0)) / \
           len(model_neg_prediction_idx)


class BaseSetCoveringMachine(object):
    def __init__(self, model_type, max_rules):
        if model_type == conjunction:
            self._add_rule_to_model = self._append_conjunction_model

# Path: core/kover/learning/common/models.py
# class BaseModel(object):
# class CARTModel(BaseModel):
# class SCMModel(BaseModel):
# class ConjunctionModel(SCMModel):
# class DisjunctionModel(SCMModel):
#     def __init__(self):
#     def predict(self, X):
# 	def predict_proba(self, X):
#     def learner(self):
#     def __str__(self):
#     def __init__(self, class_tags=None):
#     def predict(self, X):
#     def predict_proba(self, X):
#     def learner(self):
#     def _to_string(self, node=None,depth=0):
#     def __len__(self):
#     def depth(self):
#     def __init__(self):
#     def add(self, rule):
#     def predict(self, X):
#     def predict_proba(self, X):
#     def remove(self, index):
#     def example_dependencies(self):
#     def learner(self):
#     def type(self):
#     def _to_string(self, separator=" "):
#     def __eq__(self, other):
#     def __iter__(self):
#     def __len__(self):
#     def predict_proba(self, X):
#     def type(self):
#     def __str__(self):
#     def predict_proba(self, X):
#     def type(self):
#     def __str__(self):
# 
# Path: core/kover/utils.py
# def _class_to_string(instance):
#     """
#     Returns a string representation of the public attributes of a class.
#     
#     Parameters:
#     -----------
#     instance: object
#         An instance of any class.
#         
#     Returns:
#     --------
#     string_rep: string
#         A string representation of the class and its public attributes.
#         
#     Notes:
#     -----
#     Private attributes must be marked with a leading underscore.
#     """
#     return instance.__class__.__name__ + "(" + ",".join(
#         [str(k) + "=" + str(v) for k, v in instance.__dict__.iteritems() if str(k[0]) != "_"]) + ")"


# Path: core/kover/learning/learners/scm.py
import logging
import numpy as np
from math import ceil
from ..common.models import scm, conjunction, ConjunctionModel, disjunction, DisjunctionModel
from ...utils import _class_to_string

	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""





UTIL_BLOCK_SIZE = 1000000


def _compute_rule_importances(rule_classifications, model_rules_idx, training_example_idx):
    model_rule_classifications = rule_classifications.get_columns(model_rules_idx)[training_example_idx]
    model_neg_prediction_idx = np.where(np.prod(model_rule_classifications, axis=1) == 0)[0]
    return (float(len(model_neg_prediction_idx)) - model_rule_classifications[model_neg_prediction_idx].sum(axis=0)) / \
           len(model_neg_prediction_idx)


class BaseSetCoveringMachine(object):
    def __init__(self, model_type, max_rules):
        if model_type == conjunction:
            self._add_rule_to_model = self._append_conjunction_model

            self.model_type = conjunction