Browse Source

Remove of optimization module and optimization scripts

Jérôme BUISINE 10 months ago
parent
commit
ce47abdbc0
40 changed files with 22 additions and 1064 deletions
  1. 1 4
      .gitmodules
  2. 0 2
      custom_config.py
  3. 19 8
      data_attributes.py
  4. 0 68
      data_processing/generateAndTrain_maxwell_custom_optimization.sh
  5. 0 60
      optimization/.gitignore
  6. 0 8
      optimization/LICENSE
  7. 0 29
      optimization/README.md
  8. 0 0
      optimization/__init__.py
  9. 0 170
      optimization/algorithms/Algorithm.py
  10. 0 45
      optimization/algorithms/IteratedLocalSearch.py
  11. 0 41
      optimization/algorithms/LocalSearch.py
  12. 0 0
      optimization/algorithms/__init__.py
  13. 0 75
      optimization/checkpoints/BasicCheckpoint.py
  14. 0 22
      optimization/checkpoints/Checkpoint.py
  15. 0 0
      optimization/checkpoints/__init__.py
  16. 0 8
      optimization/evaluators/EvaluatorExample.py
  17. 0 0
      optimization/evaluators/__init__.py
  18. 0 48
      optimization/mainExample.py
  19. 0 7
      optimization/operators/Operator.py
  20. 0 0
      optimization/operators/__init__.py
  21. 0 11
      optimization/operators/crossovers/Crossover.py
  22. 0 31
      optimization/operators/crossovers/SimpleCrossover.py
  23. 0 0
      optimization/operators/crossovers/__init__.py
  24. 0 11
      optimization/operators/mutators/Mutation.py
  25. 0 28
      optimization/operators/mutators/SimpleBinaryMutation.py
  26. 0 35
      optimization/operators/mutators/SimpleMutation.py
  27. 0 0
      optimization/operators/mutators/__init__.py
  28. 0 40
      optimization/operators/policies/Policy.py
  29. 0 16
      optimization/operators/policies/RandomPolicy.py
  30. 0 0
      optimization/operators/policies/__init__.py
  31. 0 1
      optimization/requirements.txt
  32. 0 40
      optimization/solutions/BinarySolution.py
  33. 0 40
      optimization/solutions/CombinatoryIntegerSolution.py
  34. 0 40
      optimization/solutions/IntegerSolution.py
  35. 0 45
      optimization/solutions/Solution.py
  36. 0 0
      optimization/solutions/__init__.py
  37. 0 37
      run/runAll_maxwell_custom_optimization_attributes.sh
  38. 0 38
      run/runAll_maxwell_custom_optimization_filters.sh
  39. 2 0
      simulation/run_maxwell_simulation_filters_statistics.sh
  40. 0 56
      simulation/run_maxwell_simulation_filters_statistics_opti.sh

+ 1 - 4
.gitmodules

@@ -1,6 +1,3 @@
 [submodule "modules"]
 	path = modules
-	url = https://github.com/prise-3d/Thesis-CommonModules.git
-[submodule "optimization"]
-	path = optimization
-	url = https://github.com/prise-3d/Thesis-OptimizationModules.git
+	url = https://github.com/prise-3d/Thesis-CommonModules.git

+ 0 - 2
custom_config.py

@@ -12,8 +12,6 @@ backup_folder                           = 'backups'
 
 # variables
 features_choices_labels                 = ['filters_statistics', 'svd', 'filters_statistics_sobel', 'svd_sobel']
-optimization_filters_result_filename    = 'optimization_comparisons_filters.csv'
-optimization_attributes_result_filename = 'optimization_comparisons_attributes.csv'
 
 models_names_list                       = ["rfe_svm_model"]
 

+ 19 - 8
data_attributes.py

@@ -23,13 +23,8 @@ import custom_config as cfg
 from modules.utils import data as dt
 
 
-def get_image_features(data_type, block):
-    """
-    Method which returns the data type expected
-    """
-
-    if 'filters_statistics' in data_type:
-
+def _get_26_attributes(block):
+    
         img_width, img_height = 200, 200
 
         lab_img = transform.get_LAB_L(block)
@@ -86,8 +81,24 @@ def get_image_features(data_type, block):
 
         for stat in stats:
             data.append(stat[1])
+
+        return data   
+
+def get_image_features(data_type, block):
+    """
+    Method which returns the data type expected
+    """
+
+    data = []
+
+    if 'filters_statistics' in data_type:
+        data = _get_26_attributes(block)
+
+    if 'filters_statistics_sobel' in data_type:
+        data = _get_26_attributes(block)
         
-        data = np.array(data)
+
+    data = np.array(data) 
 
     return data
 

+ 0 - 68
data_processing/generateAndTrain_maxwell_custom_optimization.sh

@@ -1,68 +0,0 @@
-#! bin/bash
-
-if [ -z "$1" ]
-  then
-    echo "No argument supplied"
-    echo "Need of vector size"
-    exit 1
-fi
-
-if [ -z "$2" ]
-  then
-    echo "No argument supplied"
-    echo "Need of feature information"
-    exit 1
-fi
-
-if [ -z "$3" ]
-  then
-    echo "No argument supplied"
-    echo "Need of kind of data to use"
-    exit 1
-fi
-
-if [ -z "$4" ]
-  then
-    echo "No argument supplied"
-    echo "Use of filters or attributes"
-    exit 1
-fi
-
-
-size=$1
-feature=$2
-data=$3
-filter=$4
-
-
-# selection of four scenes (only maxwell)
-scenes="A, D, G, H"
-result_filename="results/optimization_comparisons_${filter}.csv"
-start=0
-end=$size
-
-#for nb_zones in {4,6,8,10,12}; do
-for nb_zones in {10,12}; do
-
-    for mode in {"svd","svdn","svdne"}; do
-        for model in {"svm_model","ensemble_model","ensemble_model_v2"}; do
-      
-            FILENAME="data/${model}_N${size}_B${start}_E${end}_nb_zones_${nb_zones}_${feature}_${mode}_${data}_${filter}"
-            MODEL_NAME="${model}_N${size}_B${start}_E${end}_nb_zones_${nb_zones}_${feature}_${mode}_${data}_${filter}"
-            CUSTOM_MIN_MAX_FILENAME="N${size}_B${start}_E${end}_nb_zones_${nb_zones}_${feature}_${mode}_${data}_${filter}_min_max"
-
-            echo $FILENAME
-
-            # only compute if necessary (perhaps server will fall.. Just in case)
-            if grep -q "${MODEL_NAME}" "${result_filename}"; then
-
-                echo "${MODEL_NAME} results already generated..."
-            else
-                python generate/generate_data_model_random_${data}.py --output ${FILENAME} --interval "${start},${end}" --kind ${mode} --feature ${feature} --scenes "${scenes}" --nb_zones "${nb_zones}" --percent 1 --renderer "maxwell" --step 40 --random 1 --custom ${CUSTOM_MIN_MAX_FILENAME}
-                
-                echo "Train ${MODEL_NAME}"
-                #python find_best_${filter}.py --data ${FILENAME} --choice ${model} &
-            fi
-        done
-    done
-done

+ 0 - 60
optimization/.gitignore

@@ -1,60 +0,0 @@
-# ---> Python
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-*$py.class
-
-# C extensions
-*.so
-
-# Distribution / packaging
-.Python
-env/
-build/
-develop-eggs/
-dist/
-downloads/
-eggs/
-.eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-*.egg-info/
-.installed.cfg
-*.egg
-
-# PyInstaller
-#  Usually these files are written by a python script from a template
-#  before PyInstaller builds the exe, so as to inject date/other infos into it.
-*.manifest
-*.spec
-
-# Installer logs
-pip-log.txt
-pip-delete-this-directory.txt
-
-# Unit test / coverage reports
-htmlcov/
-.tox/
-.coverage
-.coverage.*
-.cache
-nosetests.xml
-coverage.xml
-*,cover
-
-# Translations
-*.mo
-*.pot
-
-# Django stuff:
-*.log
-
-# Sphinx documentation
-docs/_build/
-
-# PyBuilder
-target/
-

+ 0 - 8
optimization/LICENSE

@@ -1,8 +0,0 @@
-MIT License
-Copyright (c) <year> <copyright holders>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 0 - 29
optimization/README.md

@@ -1,29 +0,0 @@
-# Thesis-OptimizationModules
-
-## Description
-
-Optimisation generic framework built for optimization problem during thesis
-
-## Modules
-
-- **algorithms:** generic and implemented OR algorithms
-- **evaluator:** example of an evaluation function to use (you have to implement your own evaluation function)
-- **solutions:** solutions used to represent problem data
-- **operators:** mutators, crossovers update of solution. This folder also had `policies` folder to manage the way of update and use solution.
-- **checkpoints:** checkpoints folder where `Checkpoint` class is available for making checkpoint every number of evaluations.
-  
-**Note:** you can pass a custom `validator` function to the algorithm in order to check is solution is always correct for your needs after an update.
-
-## How to use ?
-
-You can see an example of use in the `mainExample.py` python file. You need to clone this repository with `optimization` folder name to get it works.
-
-## Add as dependency
-
-```bash
-git submodule add https://github.com/prise-3d/Thesis-OptimizationModules.git optimization
-```
-
-## License
-
-[The MIT License](LICENSE)

+ 0 - 0
optimization/__init__.py


+ 0 - 170
optimization/algorithms/Algorithm.py

@@ -1,170 +0,0 @@
-# main imports
-import logging
-
-# Generic algorithm class
-class Algorithm():
-
-    def __init__(self, _initalizer, _evaluator, _operators, _policy, _validator, _maximise=True, _parent=None):
-        """
-        Initialize all usefull parameters for problem to solve
-        """
-
-        self.initializer = _initalizer
-        self.evaluator = _evaluator
-        self.operators = _operators
-        self.validator = _validator
-        self.policy = _policy
-        self.checkpoint = None
-
-        # other parameters
-        self.parent = _parent # parent algorithm if it's sub algorithm
-        #self.maxEvaluations = 0 # by default
-        self.maximise = _maximise
-
-        self.initRun()
-
-
-    def addCheckpoint(self, _class, _every, _filepath):
-        self.checkpoint = _class(self, _every, _filepath)
-
-    
-    def setCheckpoint(self, _checkpoint):
-        self.checkpoint = _checkpoint
-
-
-    def resume(self):
-        if self.checkpoint is None:
-            raise ValueError("Need to `addCheckpoint` or `setCheckpoint` is you want to use this process")
-        else:
-            print('Checkpoint loading is called')
-            self.checkpoint.load()
-
-
-    def initRun(self):
-        """
-        Reinit the whole variables
-        """
-
-        self.currentSolution = self.initializer()
-        
-        # evaluate current solution
-        self.currentSolution.evaluate(self.evaluator)
-
-        # keep in memory best known solution (current solution)
-        self.bestSolution = self.currentSolution
-        
-
-    def increaseEvaluation(self):
-        self.numberOfEvaluations += 1
-
-        if self.parent is not None:
-            self.parent.numberOfEvaluations += 1
-
-    
-    def getGlobalEvaluation(self):
-
-        if self.parent is not None:
-            return self.parent.numberOfEvaluations
-
-        return self.numberOfEvaluations
-
-
-    def stop(self):
-        """
-        Global stopping criteria (check for inner algorithm too)
-        """
-        if self.parent is not None:
-            return self.parent.numberOfEvaluations >= self.parent.maxEvaluations or self.numberOfEvaluations >= self.maxEvaluations
-            
-        return self.numberOfEvaluations >= self.maxEvaluations
-
-
-    def evaluate(self, solution):
-        """
-        Returns: 
-            fitness score of solution which is not already evaluated or changed
-
-        Note: 
-            if multi-objective problem this method can be updated using array of `evaluator`
-        """
-        return solution.evaluate(self.evaluator)
-
-
-    def update(self, solution, secondSolution=None):
-        """
-        Apply update function to solution using specific `policy`
-
-        Check if solution is valid after modification and returns it
-
-        Returns:
-            updated solution
-        """
-
-        # two parameters are sent if specific crossover solution are wished
-        sol = self.policy.apply(solution, secondSolution)
-
-        if(sol.isValid(self.validator)):
-            return sol
-        else:
-            logging.info("-- New solution is not valid %s" % sol)
-            return solution
-
-
-    def isBetter(self, solution):
-        """
-        Check if solution is better than best found
-
-        Returns:
-            `True` if better
-        """
-        # depending of problem to solve (maximizing or minimizing)
-        if self.maximise:
-            if self.evaluate(solution) > self.bestSolution.fitness():
-                return True
-        else:
-            if self.evaluate(solution) < self.bestSolution.fitness():
-                return True
-
-        # by default
-        return False
-
-
-    def run(self, _evaluations):
-        """
-        Run the specific algorithm following number of evaluations to find optima
-        """
-
-        self.maxEvaluations = _evaluations
-
-        self.initRun()
-
-        # check if global evaluation is used or not
-        if self.parent is not None and self.getGlobalEvaluation() != 0:
-            
-            # init number evaluations of inner algorithm depending of globalEvaluation
-            # allows to restart from `checkpoint` last evaluation into inner algorithm
-            rest = self.getGlobalEvaluation() % self.maxEvaluations
-            self.numberOfEvaluations = rest
-
-        else:
-            self.numberOfEvaluations = 0
-
-        logging.info("Run %s with %s evaluations" % (self.__str__(), _evaluations))
-
-
-    def progress(self):
-
-        if self.checkpoint is not None:
-            self.checkpoint.run()
-
-        logging.info("-- %s evaluation %s of %s (%s%%) - BEST SCORE %s" % (type(self).__name__, self.numberOfEvaluations, self.maxEvaluations, "{0:.2f}".format((self.numberOfEvaluations) / self.maxEvaluations * 100.), self.bestSolution.fitness()))
-
-
-    def information(self):
-        logging.info("-- Best %s - SCORE %s" % (self.bestSolution, self.bestSolution.fitness()))
-
-
-    def __str__(self):
-        return "%s using %s" % (type(self).__name__, type(self.bestSolution).__name__)
-
-

+ 0 - 45
optimization/algorithms/IteratedLocalSearch.py

@@ -1,45 +0,0 @@
-# main imports 
-import logging
-
-# module imports
-from .Algorithm import Algorithm
-from.LocalSearch import LocalSearch
-
-class IteratedLocalSearch(Algorithm):
-
-    def run(self, _evaluations, _ls_evaluations=100):
-
-        # by default use of mother method to initialize variables
-        super().run(_evaluations)
-
-        # enable checkpoint for ILS
-        if self.checkpoint is not None:
-            self.resume()
-
-        # passing global evaluation param from ILS
-        ls = LocalSearch(self.initializer, self.evaluator, self.operators, self.policy, self.validator, self.maximise, _parent=self)
-        
-        # set same checkpoint if exists
-        if self.checkpoint is not None:
-            ls.setCheckpoint(self.checkpoint)
-
-        # local search algorithm implementation
-        while not self.stop():
-
-            # create and search solution from local search
-            newSolution = ls.run(_ls_evaluations)
-
-            # if better solution than currently, replace it
-            if self.isBetter(newSolution):
-                self.bestSolution = newSolution
-
-            # number of evaluatins increased from LocalSearch
-            # increase number of evaluations and progress are then not necessary there
-            #self.increaseEvaluation()
-            #self.progress()
-
-            self.information()          
-
-        logging.info("End of %s, best solution found %s" % (type(self).__name__, self.bestSolution))
-
-        return self.bestSolution

+ 0 - 41
optimization/algorithms/LocalSearch.py

@@ -1,41 +0,0 @@
-# main imports
-import logging
-
-# module imports
-from .Algorithm import Algorithm
-
-class LocalSearch(Algorithm):
-
-    def run(self, _evaluations):
-
-        # by default use of mother method to initialize variables
-        super().run(_evaluations)
-
-        solutionSize = self.bestSolution.size
-
-        # local search algorithm implementation
-        while not self.stop():
-            
-            for _ in range(solutionSize):
-
-                # update solution using policy
-                # send random solution as second parameter for mutation
-                newSolution = self.update(self.bestSolution, self.initializer())
-
-                # if better solution than currently, replace it
-                if self.isBetter(newSolution):
-                    self.bestSolution = newSolution
-
-                # increase number of evaluations
-                self.increaseEvaluation()
-
-                self.progress()
-                logging.info("---- Current %s - SCORE %s" % (newSolution, newSolution.fitness()))
-
-                # stop algorithm if necessary
-                if self.stop():
-                    break
-            
-        logging.info("End of %s, best solution found %s" % (type(self).__name__, self.bestSolution))
-
-        return self.bestSolution

+ 0 - 0
optimization/algorithms/__init__.py


+ 0 - 75
optimization/checkpoints/BasicCheckpoint.py

@@ -1,75 +0,0 @@
-# main imports
-import os
-import logging
-import numpy as np
-
-# module imports
-from .Checkpoint import Checkpoint
-
-class BasicCheckpoint(Checkpoint):
-
-    def __init__(self, _algo, _every, _filepath):
-        self.algo = _algo
-        self.every = _every
-        self.filepath = _filepath
-
-
-    def run(self):
-
-        # get current best solution
-        solution = self.algo.bestSolution
-
-        currentEvaluation = self.algo.getGlobalEvaluation()
-
-        # backup if necessary
-        if currentEvaluation % self.every == 0:
-
-            logging.info("Checkpoint is done into " + self.filepath)
-
-            solutionData = ""
-            solutionSize = len(solution.data)
-
-            for index, val in enumerate(solution.data):
-                solutionData += str(val)
-
-                if index < solutionSize - 1:
-                    solutionData += ' '
-
-            line = str(currentEvaluation) + ';' + solutionData + ';' + str(solution.fitness()) + ';\n'
-
-            # check if file exists
-            if not os.path.exists(self.filepath):
-                with open(self.filepath, 'w') as f:
-                    f.write(line)
-            else:
-                with open(self.filepath, 'a') as f:
-                    f.write(line)
-
-
-    def load(self):
-
-        if os.path.exists(self.filepath):
-
-            logging.info('Load best solution from last checkpoint')
-            with open(self.filepath) as f:
-
-                # get last line and read data
-                lastline = f.readlines()[-1]
-                data = lastline.split(';')
-                
-                # get evaluation  information 
-                globalEvaluation = int(data[0])
-
-                if self.algo.parent is not None:
-                    self.algo.parent.numberOfEvaluations = globalEvaluation
-                else:
-                    self.algo.numberOfEvaluations = globalEvaluation
-
-                # get best solution data information
-                solutionData = list(map(int, data[1].split(' ')))
-                
-                self.algo.bestSolution.data = np.array(solutionData)
-                self.algo.bestSolution.score = float(data[2])
-        else:
-            print('No backup found... Start running')
-            logging.info("Can't load backup... Backup filepath not valid in Checkpoint")

+ 0 - 22
optimization/checkpoints/Checkpoint.py

@@ -1,22 +0,0 @@
-# main imports
-import os
-import logging
-
-class Checkpoint():
-
-    def __init__(self, _algo, _every, _filepath):
-        self.algo = _algo
-        self.every = _every
-        self.filepath = _filepath
-
-    def run(self):
-        """
-        Check if necessary to do backup based on `_every` variable
-        """
-        pass
-
-    def load(self):
-        """
-        Load last backup line of solution and set algorithm state at this backup
-        """
-        pass

+ 0 - 0
optimization/checkpoints/__init__.py


+ 0 - 8
optimization/evaluators/EvaluatorExample.py

@@ -1,8 +0,0 @@
-# evaluator example
-def evaluatorExample(solution):
-
-    fitness = 0
-    for index, elem in enumerate(solution.data):
-        fitness = fitness + (elem * index)
-    
-    return fitness

+ 0 - 0
optimization/evaluators/__init__.py


+ 0 - 48
optimization/mainExample.py

@@ -1,48 +0,0 @@
-# main imports
-import logging
-
-# module imports
-
-# Note: you need to import from folder dependency name
-# examples: `from optimization.solutions.BinarySolution import BinarySolution`
-
-from optimization.algorithms.IteratedLocalSearch import IteratedLocalSearch as ILS
-from optimization.solutions.BinarySolution import BinarySolution
-from optimization.evaluators.EvaluatorExample import evaluatorExample
-
-from optimization.operators.mutators.SimpleMutation import SimpleMutation
-from optimization.operators.mutators.SimpleBinaryMutation import SimpleBinaryMutation
-from optimization.operators.crossovers.SimpleCrossover import SimpleCrossover
-
-from optimization.operators.policies.RandomPolicy import RandomPolicy
-
-from optimization.checkpoints.BasicCheckpoint import BasicCheckpoint
-
-# logging configuration
-logging.basicConfig(format='%(asctime)s %(message)s', filename='example.log', level=logging.DEBUG)
-
-# default validator
-def validator(solution):
-    return True
-
-# define init random solution
-def init():
-    return BinarySolution([], 30).random(validator)
-
-filepath = "checkpoints.csv"
-
-def main():
-
-    operators = [SimpleBinaryMutation(), SimpleMutation(), SimpleCrossover()]
-    policy = RandomPolicy(operators)
-
-    algo = ILS(init, evaluatorExample, operators, policy, validator, True)
-    algo.addCheckpoint(_class=BasicCheckpoint, _every=5, _filepath=filepath)
-
-    bestSol = algo.run(425)
-
-    print("Found ", bestSol)
-
-
-if __name__ == "__main__":
-    main()

+ 0 - 7
optimization/operators/Operator.py

@@ -1,7 +0,0 @@
-# main imports
-from enum import Enum
-
-# enumeration which stores kind of operator
-class Operator(Enum):
-    MUTATOR = 1
-    CROSSOVER = 2

+ 0 - 0
optimization/operators/__init__.py


+ 0 - 11
optimization/operators/crossovers/Crossover.py

@@ -1,11 +0,0 @@
-# module imports
-from ..Operator import Operator
-
-# main mutation class
-class Crossover():
-
-    def __init__(self):
-        self.kind = Operator.CROSSOVER
-
-    def apply(self, solution, secondSolution=None):
-        raise NotImplementedError

+ 0 - 31
optimization/operators/crossovers/SimpleCrossover.py

@@ -1,31 +0,0 @@
-# main imports
-import random
-import sys
-
-# module imports
-from .Crossover import Crossover
-
-from ...solutions.BinarySolution import BinarySolution
-from ...solutions.Solution import Solution
-
-
-class SimpleCrossover(Crossover):
-
-    def apply(self, solution, secondSolution=None):
-        size = solution.size
-
-        # copy data of solution
-        firstData = solution.data.copy()
-        secondData = secondSolution.data.copy()
-
-        splitIndex = int(size / 2)
-        
-        if random.uniform(0, 1) > 0.5:
-            firstData[splitIndex:(size - 1)] = firstData[splitIndex:(size - 1)]
-            currentData = firstData
-        else:
-            secondData[splitIndex:(size - 1)] = firstData[splitIndex:(size - 1)]
-            currentData = secondData
-
-        # create solution of same kind with new data
-        return globals()[type(solution).__name__](currentData, size)

+ 0 - 0
optimization/operators/crossovers/__init__.py


+ 0 - 11
optimization/operators/mutators/Mutation.py

@@ -1,11 +0,0 @@
-# module imports
-from ..Operator import Operator
-
-# main mutation class
-class Mutation():
-
-    def __init__(self):
-        self.kind = Operator.MUTATOR
-
-    def apply(self, solution):
-        raise NotImplementedError

+ 0 - 28
optimization/operators/mutators/SimpleBinaryMutation.py

@@ -1,28 +0,0 @@
-# main imports
-import random
-import sys
-
-# module imports
-from .Mutation import Mutation
-
-from ...solutions.BinarySolution import BinarySolution
-from ...solutions.Solution import Solution
-
-class SimpleBinaryMutation(Mutation):
-
-    def apply(self, solution):
-        size = solution.size
-
-        cell = random.randint(0, size - 1)
-
-        # copy data of solution
-        currentData = solution.data.copy()
-
-        # swicth values
-        if currentData[cell]:
-            currentData[cell] = 0
-        else:
-            currentData[cell] = 1
-
-        # create solution of same kind with new data
-        return globals()[type(solution).__name__](currentData, size)

+ 0 - 35
optimization/operators/mutators/SimpleMutation.py

@@ -1,35 +0,0 @@
-# main imports
-import random
-import sys
-
-# module imports
-from .Mutation import Mutation
-
-from ...solutions.BinarySolution import BinarySolution
-from ...solutions.Solution import Solution
-
-
-class SimpleMutation(Mutation):
-
-    def apply(self, solution):
-        size = solution.size
-
-        firstCell = 0
-        secondCell = 0
-
-        # copy data of solution
-        currentData = solution.data.copy()
-
-        while firstCell == secondCell:
-            firstCell = random.randint(0, size - 1) 
-            secondCell = random.randint(0, size - 1)
-
-        temp = currentData[firstCell]
-
-        # swicth values
-        currentData[firstCell] = currentData[secondCell]
-        currentData[secondCell] = temp
-        
-        # create solution of same kind with new data
-        return globals()[type(solution).__name__](currentData, size)
-

+ 0 - 0
optimization/operators/mutators/__init__.py


+ 0 - 40
optimization/operators/policies/Policy.py

@@ -1,40 +0,0 @@
-# main imports
-import logging
-
-# module imports
-from ..Operator import Operator
-
-# define policy to choose `operator` function at current iteration
-class Policy():
-
-    # here you can define your statistical variables for choosing next operator to apply
-
-    def __init__(self, _operators):
-        self.operators = _operators
-
-
-    def select(self):
-        """
-        Select specific operator to solution and returns solution
-        """
-        raise NotImplementedError
-        
-    def apply(self, solution, secondSolution=None):
-        """
-        Apply specific operator chosen to solution and returns solution
-        """
-        
-        operator = self.select()
-
-        logging.info("---- Applying %s on %s" % (type(operator).__name__, solution))
-
-        # check kind of operator
-        if operator.kind == Operator.CROSSOVER:
-            newSolution = operator.apply(solution, secondSolution)
-        
-        if operator.kind == Operator.MUTATOR:
-            newSolution = operator.apply(solution)
-
-        logging.info("---- Obtaining %s" % (solution))
-
-        return newSolution

+ 0 - 16
optimization/operators/policies/RandomPolicy.py

@@ -1,16 +0,0 @@
-# main imports
-import random
-
-# module imports
-from .Policy import Policy
-
-class RandomPolicy(Policy):
-
-    def select(self):  
-
-        # choose operator randomly
-        index = random.randint(0, len(self.operators) - 1)
-        return self.operators[index]
-
-
-        

+ 0 - 0
optimization/operators/policies/__init__.py


+ 0 - 1
optimization/requirements.txt

@@ -1 +0,0 @@
-numpy

+ 0 - 40
optimization/solutions/BinarySolution.py

@@ -1,40 +0,0 @@
-# main imports
-import numpy as np
-
-# modules imports
-from .Solution import Solution
-
-
-# Solution which stores solution data as binary array
-class BinarySolution(Solution):
-
-    def __init__(self, _data, _size):
-        """
-        Initialize data of solution using specific data
-
-        - `data` field is array of binary values
-        - `size` field is the size of array binary values
-        """
-
-        self.data = _data
-        self.size = _size
-
-
-    def random(self, _validator):
-        """
-        Intialize binary array using size solution data
-
-        Use of validator to generate valid random solution
-        """
-
-        self.data = np.random.randint(2, size=self.size)
-
-        while not self.isValid(_validator):
-            self.data = np.random.randint(2, size=self.size)
-
-        return self
-
-
-    def __str__(self):
-        return "Binary solution %s" % (self.data)
-        

+ 0 - 40
optimization/solutions/CombinatoryIntegerSolution.py

@@ -1,40 +0,0 @@
-# main imports
-import numpy as np
-
-# modules imports
-from .Solution import Solution
-
-
-# Solution which stores solution data as combinatory integer array
-class CombinatoryIntegerSolution(Solution):
-
-    def __init__(self, _data, _size):
-        """
-        Initialize data of solution using specific data
-
-        - `data` field is array of integer values
-        - `size` field is the size of array integer values
-        """
-
-        self.data = _data
-        self.size = _size
-
-
-    def random(self, _validator):
-        """
-        Intialize combinatory integer array using size solution data
-
-        Use of validator to generate valid random solution
-        """
-
-        self.data = np.random.shuffle(np.arange(self.size))
-
-        while not self.isValid(_validator):
-            self.data = np.random.shuffle(np.arange(self.size))
-
-        return self
-
-
-    def __str__(self):
-        return "Combinatory integer solution %s" % (self.data)
-        

+ 0 - 40
optimization/solutions/IntegerSolution.py

@@ -1,40 +0,0 @@
-# main imports
-import numpy as np
-
-# modules imports
-from .Solution import Solution
-
-
-# Solution which stores solution data as integer array
-class IntegerSolution(Solution):
-
-    def __init__(self, _data, _size):
-        """
-        Initialize data of solution using specific data
-
-        - `data` field is array of integer values
-        - `size` field is the size of array integer values
-        """
-
-        self.data = _data
-        self.size = _size
-
-
-    def random(self, _validator):
-        """
-        Intialize integer array using size solution data
-
-        Use of validator to generate valid random solution
-        """
-
-        self.data = np.random.randint(self.size, size=self.size)
-
-        while not self.isValid(_validator):
-            self.data = np.random.randint(self.size, size=self.size)
-
-        return self
-
-
-    def __str__(self):
-        return "Integer solution %s" % (self.data)
-        

+ 0 - 45
optimization/solutions/Solution.py

@@ -1,45 +0,0 @@
-# Generic solution class 
-class Solution():
-
-    def __init__(self, _data, _size):
-        """
-        Initialize data of solution using specific data
-
-        Note : `data` field can be anything, such as array/list of integer
-        """
-        self.data = _data
-        self.size = _size
-        self.score = None
-        
-
-    def isValid(self, _validator):
-        """
-        Use of custom method which validates if solution is valid or not
-        """
-        return _validator(self)
-
-
-    def evaluate(self, _evaluator):
-        """
-        Evaluate function using specific `_evaluator`
-        """
-        self.score = _evaluator(self)
-        return self.score
-
-
-    def fitness(self):
-        """
-        Returns fitness score
-        """
-        return self.score
-
-
-    def random(self, _validator):
-        """
-        Initialize solution using random data
-        """
-        raise NotImplementedError
-
-
-    def __str__(self):
-        print("Generic solution with ", self.data)

+ 0 - 0
optimization/solutions/__init__.py


+ 0 - 37
run/runAll_maxwell_custom_optimization_attributes.sh

@@ -1,37 +0,0 @@
-#! bin/bash
-
-# erase "results/optimization_comparisons.csv" file and write new header
-file_path='results/optimization_comparisons_attributes.csv'
-list="all, center, split"
-
-if [ -z "$1" ]
-  then
-    echo "No argument supplied"
-    echo "Need argument from [${list}]"
-    exit 1
-fi
-
-if [[ "$1" =~ ^(all|center|split)$ ]]; then
-    echo "$1 is in the list"
-else
-    echo "$1 is not in the list"
-fi
-
-data=$1
-erased=$2
-
-if [ "${erased}" == "Y" ]; then
-    echo "Previous data file erased..."
-    rm ${file_path}
-    mkdir -p results
-    touch ${file_path}
-
-    # add of header
-    echo 'data_file; ils_iteration; ls_iteration; best_solution; nb_attributes; nb_filters; fitness (roc test);' >> ${file_path}
-fi
-
-size=26
-feature="filters_statistics"
-filter="attributes"
-
-bash data_processing/generateAndTrain_maxwell_custom_optimization.sh ${size} ${feature} ${data} ${filter}

+ 0 - 38
run/runAll_maxwell_custom_optimization_filters.sh

@@ -1,38 +0,0 @@
-#! bin/bash
-
-# erase "results/optimization_comparisons.csv" file and write new header
-file_path='results/optimization_comparisons_filters.csv'
-list="all, center, split"
-
-if [ -z "$1" ]
-  then
-    echo "No argument supplied"
-    echo "Need argument from [${list}]"
-    exit 1
-fi
-
-if [[ "$1" =~ ^(all|center|split)$ ]]; then
-    echo "$1 is in the list"
-else
-    echo "$1 is not in the list"
-fi
-
-data=$1
-erased=$2
-
-if [ "${erased}" == "Y" ]; then
-    echo "Previous results file erased..."
-    rm ${file_path}
-    mkdir -p results
-    touch ${file_path}
-
-    # add of header
-    echo 'data_file; ils_iteration; ls_iteration; best_solution; nb_filters; fitness (roc test);' >> ${file_path}
-
-fi
-
-size=26
-feature="filters_statistics"
-filter="filters"
-
-bash data_processing/generateAndTrain_maxwell_custom_optimization.sh ${size} ${feature} ${data} ${filter}

+ 2 - 0
simulation/run_maxwell_simulation_filters_statistics.sh

@@ -7,6 +7,8 @@ simulate_models="simulate_models.csv"
 scenes="A,D,G,H"
 
 size="26"
+declare -A featuresSize
+animals=( ["filters_statistics"]="26" ["svd"]="200" ["filters_statistics_sobel"]="27" ["svd_sobel"]="201")
 
 # for feature in {"lab","mscn","low_bits_2","low_bits_3","low_bits_4","low_bits_5","low_bits_6","low_bits_4_shifted_2","ica_diff","svd_trunc_diff","ipca_diff","svd_reconstruct"}; do
 feature="filters_statistics"

+ 0 - 56
simulation/run_maxwell_simulation_filters_statistics_opti.sh

@@ -1,56 +0,0 @@
-#! bin/bash
-
-# file which contains model names we want to use for simulation
-list="attributes, filters"
-
-if [ -z "$1" ]
-  then
-    echo "No argument supplied"
-    echo "Need argument from [${list}]"
-    exit 1
-fi
-
-
-# selection of four scenes (only maxwell)
-scenes="A, D, G, H"
-size="26"
-feature="filters_statistics"
-filter=$1
-
-simulate_models="simulate_models_${filter}_all.csv"
-
-
-for nb_zones in {4,6,8,10,12}; do
-    for mode in {"svd","svdn","svdne"}; do
-        for model in {"svm_model","ensemble_model","ensemble_model_v2"}; do
-            for data in {"all","center","split"}; do
-
-                FILENAME="data/${model}_N${size}_B0_E${size}_nb_zones_${nb_zones}_${feature}_${mode}_${data}_${filter}"
-                MODEL_NAME="${model}_N${size}_B0_E${size}_nb_zones_${nb_zones}_${feature}_${mode}_${data}_${filter}"
-                CUSTOM_MIN_MAX_FILENAME="N${size}_B0_E${size}_nb_zones_${nb_zones}_${feature}_${mode}_${data}_${filter}_min_max"
-
-                # only compute if necessary (perhaps server will fall.. Just in case)
-                if grep -q "${FILENAME}" "${simulate_models}"; then
-
-                    echo "Found ${FILENAME}"
-                    line=$(grep -n ${FILENAME} ${simulate_models})
-
-                    # extract solution
-                    IFS=\; read -a fields <<<"$line"
-
-                    SOLUTION=${fields[1]}
-
-                    echo "Run simulation for ${MODEL_NAME}... with ${SOLUTION}"
-
-                    # Use of already generated model
-                    python generate/generate_data_model_random_${data}.py --output ${FILENAME} --interval "0,${size}" --kind ${mode} --feature ${feature} --scenes "${scenes}" --nb_zones "${nb_zones}" --percent 1 --renderer "maxwell" --step 10 --random 1 --custom ${CUSTOM_MIN_MAX_FILENAME}
-                    python train_model_${filter}.py --data ${FILENAME} --output ${MODEL_NAME} --choice ${model} --solution "${SOLUTION}"
-
-                    python prediction/predict_seuil_expe_maxwell_curve_opti.py --solution "${SOLUTION}" --model "saved_models/${MODEL_NAME}.joblib" --mode "${mode}" --feature ${feature} --custom ${CUSTOM_MIN_MAX_FILENAME} --filter ${filter}
-
-                    #python others/save_model_result_in_md_maxwell.py --solution "${SOLUTION}" --model "saved_models/${MODEL_NAME}.joblib" --mode "${mode}" --feature ${feature}
-                fi
-            done
-        done
-    done
-done