Bladeren bron

Removed not needed code.

Kristian Schultz 4 jaren geleden
bovenliggende
commit
3361083535

+ 0 - 160
library/NNSearch/MaxHeap.py

@@ -1,160 +0,0 @@
-
-class MaxHeap:
-    def __init__(self, maxSize=None, isGreaterThan=None, smalestValue=(-1,0.0)):
-        self.heap = []
-        self.size = 0
-        self.maxSize = maxSize
-        self.isGreaterThan = isGreaterThan if isGreaterThan is not None else (lambda a, b: a > b)
-        self.smalestValue = smalestValue
-        self.indices = set()
-        self.wasChanged = False
-        self.insert(smalestValue)
-
-    def copy(self):
-        c = MaxHeap(maxSize=self.maxSize, isGreaterThan=self.isGreaterThan, smalestValue=self.smalestValue)
-        c.heap = self.heap.copy()
-        c.size = self.size
-        c.indices = self.indices.copy()
-        c.wasChanged = self.wasChanged
-        return c
-
-    def insert(self, v):
-        if self.maxSize is not None and self.size >= self.maxSize:
-            return self.replaceMax(v)
-
-        if v[0] in self.indices:
-            return False
-
-        self.indices.add(v[0])
-        pos = self.size
-        self.size += 1
-        self.heap.append(v)
-        while pos > 0:
-            w = self.heap[pos // 2]
-            if not self.isGreaterThan(v, w):
-                break
-            self.heap[pos] = w
-            pos = pos // 2
-            self.heap[pos] = v
-        self.wasChanged = True
-        return True
-
-
-    def childPos(self, pos):
-        c = (pos + 1) * 2
-        return (c - 1, c)
-
-
-    def removeMax(self):
-        if self.heap == []:
-            self.size = 0
-            return False
-        
-        x = self.heap[0]
-        self.indices.remove(x[0])
-
-        self.heap[0] = self.heap[-1]
-        self.heap = self.heap[:-1]
-        self.size -= 1
-
-        x = self.heap[0]
-        pos = 0
-        size = self.size
-
-        while pos < size:
-            (left, right) = self.childPos(pos)
-
-            if left >= size:
-                break
-
-            y = self.heap[left]
-            if right >= size:
-                if self.isGreaterThan(y, x):
-                    self.heap[pos] = y
-                    self.heap[left] = x
-                break
-
-            z = self.heap[right]
-            (best, v) = (left, y) if self.isGreaterThan(y, z) else (right, z)
-
-            if not self.isGreaterThan(v, x):
-                break
-
-            self.heap[pos] = v
-            self.heap[best] = x
-            pos = best
-
-        self.wasChanged = True
-        return True
-
-
-    def replaceMax(self, x):
-        if self.heap == []:
-            self.heap = [x]
-            self.size = 1
-            self.indices.add(x[0])
-            self.wasChanged = True
-            return True
-        
-        if x[0] in self.indices:
-            return False
-
-        if self.isGreaterThan(x, self.heap[0]):
-            return False
-
-        self.indices.remove((self.heap[0])[0])
-        self.indices.add(x[0])
-        self.heap[0] = x
-        pos = 0
-        size = len(self.heap)
-
-        while pos < size:
-            (left, right) = self.childPos(pos)
-
-            if left >= size:
-                break
-
-            y = self.heap[left]
-            if right >= size:
-                if self.isGreaterThan(y, x):
-                    self.heap[pos] = y
-                    self.heap[left] = x
-                break
-
-            z = self.heap[right]
-            (best, v) = (left, y) if self.isGreaterThan(y, z) else (right, z)
-
-            if not self.isGreaterThan(v, x):
-                break
-
-            self.heap[pos] = v
-            self.heap[best] = x
-            pos = best
-
-        self.wasChanged = True
-        return True
-
-    def getMax(self):
-        if self.heap == []:
-            return self.smalestValue
-        return self.heap[0]
-
-
-    def setMaxSize(self, maxSize):
-        self.maxSize = maxSize
-        while self.size > maxSize:
-            self.removeMax()
-
-    def toArray(self, mapFn=None):
-        return list(self.indices)
-
-    def toOrderedArray(self):
-        c = self.copy()
-        result = []
-        while c.size > 0:
-            result.append(c.getMax())
-            c.removeMax()
-        return result.reverse()
-
-    def length(self):
-        return self.size

+ 0 - 368
library/NNSearch_experimental.py

@@ -1,368 +0,0 @@
-import math
-from ctypes import cdll, c_uint, c_double, c_void_p
-
-import tensorflow as tf
-import tensorflow.keras.layers as L
-import numpy as np
-import numpy.ctypeslib as npct
-
-array_2d_uint = npct.ndpointer(dtype=np.uint, ndim=2, flags='CONTIGUOUS')
-array_1d_double = npct.ndpointer(dtype=np.double, ndim=1, flags='CONTIGUOUS')
-array_2d_double = npct.ndpointer(dtype=np.double, ndim=2, flags='CONTIGUOUS')
-
-
-from sklearn.neighbors import NearestNeighbors
-from library.timing import timing
-from library.MaxHeap import MaxHeap
-
-
-nbhLib = cdll.LoadLibrary("./library/c/libNeighborhood.so")
-nbhLib.Neighborhood.rettype = None
-nbhLib.Neighborhood.argtypes = [c_uint, c_uint, c_uint, array_2d_double, array_2d_uint]
-
-#nbhLib.NeighborhoodHeuristic.rettype = None
-#nbhLib.NeighborhoodHeuristic.argtypes = [c_uint, c_uint, c_uint, array_2d_double, array_2d_uint]
-
-
-
-def scalarP(a, b):
-    return sum(map(lambda c: c[0] * c[1], zip(a, b)))
-
-def norm2(v):
-    return sum(map(lambda z: z*z, v))
-
-def dist(x,y):
-    return norm2(x - y)
-
-def maxby(data, fn, startValue=0.0):
-    m = startValue
-    for v in data:
-        m = max(m, fn(v))
-    return m
-
-def distancesToPoint(p, points):
-    w = np.array(np.repeat([p], len(points), axis=0))
-    d = L.Subtract()([w, np.array(points)])
-    t = L.Dot(axes=(1,1))([d,d])
-    # As the concrete distance is not needed and sqrt(x) is strict monotone
-    # we avoid here unneccessary calculating of expensive roots.
-    return t.numpy()
-
-
-def calculateCenter(points):
-    if points.shape[0] == 1:
-        return points[0]
-    return tf.keras.layers.Average()(np.array(points)).numpy()
-
-
-def centerPoints(points):
-    points = np.array(points)
-    center = L.Average()(list(points)).numpy()
-    ctr = np.array(np.repeat([center], points.shape[0], axis=0))
-    return L.Subtract()([ctr, points]).numpy()
-    
-
-def maxNormPoints(points):
-    points = np.array(points)
-    a = L.Lambda(lambda x: np.abs(x))(points)
-    a = L.Reshape((points.shape[1], 1))(a)
-    m = L.GlobalMaxPooling1D()(a)
-    m = L.Reshape((1,))
-    return m.numpy()
-
-
-def twoNormSquaredPoints(points):
-    points = np.array(points)
-    return L.Dot(axes=(1,1))([points,points]).numpy()
-    
-
-def twoNormPoints(points):
-    points = np.array(points)
-    nsq = L.Dot(axes=(1,1))([points,points])
-    return L.Lambda(lambda x: np.sqrt(x))(points).numpy()
-
-
-def norms(points):
-    points = np.array(points)
-    a = L.Lambda(lambda x: np.abs(x))(points)
-    a = L.Reshape((points.shape[1], 1))(a)
-    m = L.GlobalMaxPooling1D()(a)
-    m = L.Reshape((1,))(m)
-    nsq = L.Dot(axes=(1,1))([points,points])
-    return L.Concatenate()([m, nsq]).numpy()
-
-
-class NNSearch:
-    def __init__(self, nebSize=5, timingDict=None):
-        self.nebSize = nebSize
-        self.neighbourhoods = []
-        self.timingDict = timingDict
-
-
-    def timerStart(self, name):
-        if self.timingDict is not None:
-            if name not in self.timingDict:
-                self.timingDict[name] = timing(name)
-
-            self.timingDict[name].start()
-
-    def timerStop(self, name):
-        if self.timingDict is not None:
-            if name in self.timingDict:
-                self.timingDict[name].stop()
-
-    def neighbourhoodOfItem(self, i):
-        return self.neighbourhoods[i]
-
-
-    def fit(self, X, nebSize=None):
-        self.timerStart("NN_fit_all")
-        self.fit_chained(X, nebSize)
-        #self.fit_bruteForce_np(X, nebSize)
-        self.timerStop("NN_fit_all")
-       
-    def fit_optimized(self, X, nebSize=None):
-        self.timerStart("NN_fit_all")
-        if nebSize == None:
-            nebSize = self.nebSize
-
-        nPoints = len(X)
-        nFeatures = len(X[0])
-
-        if nFeatures > 15 or nebSize >= (nPoints // 2):
-            print("Using brute force")
-            self.fit_bruteForce_np(X, nebSize)
-        else:
-            print("Using chained")
-            self.fit_chained(X, nebSize)
-        self.timerStop("NN_fit_all")
-
-
-    def fit_bruteForce(self, X, nebSize=None):
-        if nebSize == None:
-            nebSize = self.nebSize
-
-        self.timerStart("NN_fit_bf_init")
-        isGreaterThan = lambda x, y: x[1] > y[1]
-        self.neighbourhoods = [MaxHeap(nebSize, isGreaterThan, (i, 0.0)) for i in range(len(X))]
-        self.timerStop("NN_fit_bf_init")
-
-        self.timerStart("NN_fit_bf_loop")
-        for (i, x) in enumerate(X):
-            nbh = self.neighbourhoods[i]
-
-            for (j, y) in enumerate(X[i+1:]):
-                j += i + 1
-                self.timerStart("NN_fit_bf_dist")
-                d = dist(x,y)
-                self.timerStop("NN_fit_bf_dist")
-                self.timerStart("NN_fit_bf_insert")
-                nbh.insert((j,d))
-                self.neighbourhoods[j].insert((i,d))
-                self.timerStop("NN_fit_bf_insert")
-
-            self.timerStart("NN_fit_bf_toList")
-            self.neighbourhoods[i] = nbh.toArray(lambda v: v[0])
-            self.timerStop("NN_fit_bf_toList")
-        self.timerStop("NN_fit_bf_loop")
-
-
-    def fit_bruteForce_np(self, X, nebSize=None):
-        self.timerStart("NN_fit_bfnp_init")
-        numOfPoints = len(X)
-        nFeatures = len(X[0])
-
-        tX = tf.convert_to_tensor(X)
-
-        def distancesTo(x):
-            w = np.repeat([x], numOfPoints, axis=0)
-            d = tf.keras.layers.Subtract()([w,tX])
-            t = tf.keras.layers.Dot(axes=(1,1))([d,d])
-            return t.numpy()
-
-        if nebSize == None:
-            nebSize = self.nebSize
-
-        isGreaterThan = lambda x, y: x[1] > y[1]
-        self.neighbourhoods = [MaxHeap(nebSize, isGreaterThan, (i, 0.0)) for i in range(len(X))]
-        self.timerStop("NN_fit_bfnp_init")
-
-        self.timerStart("NN_fit_bfnp_loop")
-        for (i, x) in enumerate(X):
-            self.timerStart("NN_fit_bfnp_dist")
-            distances = distancesTo(x)
-            self.timerStop("NN_fit_bfnp_dist")
-            nbh = self.neighbourhoods[i]
-
-            for (j, y) in enumerate(X[i+1:]):
-                j += i + 1
-                d = distances[j]
-                self.timerStart("NN_fit_bfnp_insert")
-                nbh.insert((j,d))
-                self.neighbourhoods[j].insert((i,d))
-                self.timerStop("NN_fit_bfnp_insert")
-
-            self.timerStart("NN_fit_bfnp_toList")
-            self.neighbourhoods[i] = nbh.toArray(lambda v: v[0])
-            self.timerStop("NN_fit_bfnp_toList")
-        self.timerStop("NN_fit_bfnp_loop")
-
-
-    def fit_chained(self, X, nebSize=None):
-        self.timerStart("NN_fit_chained_init")
-        if nebSize == None:
-            nebSize = self.nebSize
-
-        nPoints = len(X)
-        nFeatures = len(X[0])
-
-        neigh = NearestNeighbors(n_neighbors=nebSize)
-        neigh.fit(X)
-        self.timerStop("NN_fit_chained_init")
-        self.timerStart("NN_fit_chained_toList")
-        self.neighbourhoods = [
-                (neigh.kneighbors([x], nebSize, return_distance=False))[0]
-                for (i, x) in enumerate(X)
-                ]
-        self.timerStop("NN_fit_chained_toList")
-
-
-    def fit_cLib(self, X, nebSize=None):
-        self.timerStart("NN_fit_cLib_init")
-        if nebSize == None:
-            nebSize = self.nebSize
-        
-        nbh = np.array([np.zeros(nebSize, dtype=np.uint) for i in range(X.shape[0])])
-        self.timerStop("NN_fit_cLib_init")
-        self.timerStart("NN_fit_cLib_call")
-        nbhLib.Neighborhood(nebSize, X.shape[0], X.shape[1], X, nbh)
-        self.timerStop("NN_fit_cLib_call")
-        self.timerStart("NN_fit_cLib_list")
-        self.neighbourhoods = list(nbh)
-        self.timerStop("NN_fit_cLib_list")
-
-    # def fit_cLibHeuristic(self, X, nebSize=None):
-    #     self.timerStart("NN_fit_cLib_init")
-    #     if nebSize == None:
-    #         nebSize = self.nebSize
-    #     
-    #     nbh = np.array([np.zeros(nebSize, dtype=np.uint) for i in range(X.shape[0])])
-    #     self.timerStop("NN_fit_cLib_init")
-    #     self.timerStart("NN_fit_cLib_call")
-    #     nbhLib.NeighborhoodHeuristic(nebSize, X.shape[0], X.shape[1], X, nbh)
-    #     self.timerStop("NN_fit_cLib_call")
-    #     self.timerStart("NN_fit_cLib_list")
-    #     self.neighbourhoods = list(nbh)
-    #     self.timerStop("NN_fit_cLib_list")
-        
-
-    # ===============================================================
-    # Heuristic search
-    # ===============================================================
-    def fit_heuristic(self, X, nebSize=None, debugLayer=0, withDouble=True):
-        if nebSize == None:
-            nebSize = self.nebSize
-
-        self.timerStart("NN_fit_heuristic_init")
-        nPoints = len(X)
-        nFeatures = len(X[0])
-        nHeuristic = max(1, int(math.log(nFeatures)))
-        isGreaterThan = lambda x, y: x[1] > y[1]
-        self.neighbourhoods = [MaxHeap(maxSize=nebSize, isGreaterThan=isGreaterThan, smalestValue=(i, 0.0)) for i in range(len(X))]
-
-
-        self.timerStart("NN_fit_heuristic_lineStart")
-        z = X[0]
-        farest = 0
-        bestDist = 0.0
-        for (i, x) in enumerate(X):
-            d = dist(x, z)
-            if d > bestDist:
-                farest = i
-                bestDist = d
-
-        lineStart = farest
-        z = X[lineStart]
-        self.timerStop("NN_fit_heuristic_lineStart")
-
-        # print(f"lineStart: {lineStart}@{z} ... {bestDist}")
-
-        self.timerStart("NN_fit_heuristic_lineEnd")
-        bestDist = 0.0
-        for (i, x) in enumerate(X):
-            d = dist(x, z)
-            if d > bestDist:
-                farest = i
-                bestDist = d
-
-        lineEnd = farest
-        self.timerStop("NN_fit_heuristic_lineEnd")
-
-        self.timerStart("NN_fit_heuristic_line")
-        # print(f"lineEnd: {lineEnd}@{X[lineEnd]} ... {bestDist}")
-        u = (X[lineEnd] - z)
-        uFactor = (1 / math.sqrt(norm2(u)))
-        u = uFactor * u
-        # print(f"u: {u} ... {norm2(u)}")
-
-        def heuristic(i,x):
-            p = z + (scalarP(u, x - z) * u)
-            dz = math.sqrt(dist(z, p))
-            dx = math.sqrt(dist(x, p)) 
-            return (i, dz, dx)
-
-        line = [heuristic(i, x) for (i,x) in enumerate(X) ]
-        line.sort(key= lambda a: a[1])
-        self.timerStop("NN_fit_heuristic_line")
-        self.timerStop("NN_fit_heuristic_init")
-
-        self.timerStart("NN_fit_heuristic_loop")
-        s = 0
-        ff = False
-        ptsDone = set()
-        for (i,(xi, di, dix)) in enumerate(line):
-            self.timerStart("NN_fit_heuristic_loop_init")
-            h = self.neighbourhoods[xi]
-            z = X[xi]
-            self.timerStop("NN_fit_heuristic_loop_init")
-            ptsDone.add(xi)
-
-            self.timerStart("NN_fit_heuristic_loop_distance")
-            ll = [(xj, norm2([dj - di, djx - dix])) for (xj, dj, djx) in line[i:]]
-            # ll = [(xj, dist(
-            #     np.array([di, dix] + list(X[xi][0:nHeuristic])),
-            #     np.array([dj, djx] + list(X[xj][0:nHeuristic]))))
-            #     for (xj, dj, djx) in line[1:]
-            #     ]
-            ll.sort(key = lambda a: a[1])
-            kk = distancesToPoint(z, [X[j] for (j, _) in ll])
-            self.timerStop("NN_fit_heuristic_loop_distance")
-
-            for (d, (xj, djx)) in zip(kk, ll):
-                ign = h.size >= nebSize and djx > h.getMax()[1]
-                if ign:
-                    break
-                else:
-                    #d = dist(X[xj], z)
-                    self.timerStart("NN_fit_heuristic_insert")
-                    s += 1
-                    h.insert((xj, d))
-                    k = self.neighbourhoods[xj]
-                    if not isinstance(k, list):
-                        k.insert((xi, d))
-                    self.timerStop("NN_fit_heuristic_insert")
-    
-                # if xi == debugLayer:
-                #     d = dist(X[xj], z)
-                #     hint = ""
-                #     if djx > d:
-                #         hint += "!!"
-                #     if ign:
-                #         hint += "*"
-                #     print(f"xj:{xj}   dx:{h.getMax()[1]:0.1f}   djx:{djx:0.1f}  d:{d:0.1f}" + hint)
-            self.timerStart("NN_fit_heuristic_toArray")
-            self.neighbourhoods[xi] = h.toArray()
-            self.timerStop("NN_fit_heuristic_toArray")
-        self.timerStop("NN_fit_heuristic_loop")
-        print(f"calculated distances: {s} / {nPoints * (nPoints - 1)}")
-                    

+ 1 - 1
library/analysis.py

@@ -1,6 +1,6 @@
 from library.exercise import Exercise
 from library.dataset import DataSet, TrainTestData
-from library.generators import ProWRAS, SimpleGan, Repeater, SpheredNoise, ConvGeN, StupidToyListGan, CtGAN, CtabGan
+from library.generators import ProWRAS, SimpleGan, Repeater, ConvGeN, CtGAN, CtabGan
 
 import pickle
 import numpy as np

+ 0 - 106
library/c/Heuristic.c

@@ -1,106 +0,0 @@
-#include "MaxHeap.h"
-#include "utils.h"
-
-#define Point(i)    (&(data[i * nFeatures]))
-
-
-pyWord findFarestPointTo(SearchParams params, pyReal * point) {
-    pyReal d, bestDist = 0.0;
-    pyWord i, bestIdx = 0 - 1;
-
-    for(i = 0 ; i < params->nPoints ; i ++ ) {
-        d = distSquared(point, Point(i));
-        if (d > bestDist) {
-            bestDist = d;
-            bestIdx = i;
-        }
-    }
-
-    return bestIdx;
-}
-
-
-
-void NeighborhoodHeuristic(const pyWord nbhSize, const pyWord nPoints, const pyWord nFeatures, const pyReal * data, pyWord * neighborhoods) {
-    SearchParams params = {
-        .nbhSize = nbhSize,
-        .nPoints = nPoints,
-        .nFeatures = nFeatures,
-        .data = data,
-        .neighborhoods = neighborhoods
-    };
-
-    int success = 0;
-    pyWord i, j;
-    pyReal d;
-    pyReal lineVector = NULL;
-    pyReal accu = NULL;
-
-    if(initNbhHeaps(&params)) {
-        return;
-    }
-
-    do {
-
-        const pyWord lineStartIdx = findFarestPointTo(params, Point(0));
-        if(lineStartIdx >= params->nPoints) {
-            break;
-        }
-
-        pyReal * lineStartPoint = Point(lineStartIdx);
-        const pyWord lineEndIdx = findFarestPointTo(params, lineStartPoint);
-        pyReal * lineEndPoint = Point(lineEndIdx);
-
-
-        pyReal lineVector * = malloc(params->nFeatures * sizeof(pyReal));
-        if(!lineVector) {
-            break;
-        }
-        lineVector = vecSub(nFeatures, lineEndPoint, lineStartPoint); 
-        d = vecNorm(lineVector);
-        if(d == 0.0) {
-            break;
-        }
-        vecScale(nFeatures, lineVector, 1.0 / d, lineVector);
-
-
-        pyReal accu * = malloc(params->nFeatures * sizeof(pyReal));
-        if(!accu) {
-            break;
-        }
-
-        // Berechne alle Distanzen
-        for(i = 0; i < nPoints; i ++) {
-            const pyReal *x = Point(i);
-
-            vecSub(nFeatures, accu, x, lineStartPoint);
-            d = vecScalarProduct(nFeatures, lineVector, accu);
-            vecScale(nFeatures, accu, d, lineVector);
-            vecAdd(nFeatures, accu, accu, lineStartPoint);
-
-            const pyReal di1 = sqrt(distSquared(accu, lineStartPoint, nFeatures));
-            const pyReal di2 = sqrt(distSquared(accu, x, nFeatures));
-
-            
-            for(j = i + 1; j < nPoints; j ++) {
-                const pyReal * y = Point(j);
-                d = distSquared(x, y, nFeatures);
-                
-                maxHeap_insert(&(params.nbhHeaps.heaps[i]), j, d);
-                maxHeap_insert(&(params.nbhHeaps.heaps[j]), i, d);
-            }
-        }
-    } while(0);
-
-    if(lineVector) {
-        free(lineVector);
-    }
-
-    if(!success) {
-        nbhSearchBruteForce(&params);
-    }
-    
-    freeNbhHeaps(&params);
-}
-
-

+ 0 - 50
library/c/LinAlgebra.c

@@ -1,50 +0,0 @@
-#include "types.h"
-#include <math.h>
-
-pyReal vecScalarProduct(const pyWord size, const pyReal * a, const pyReal * b) {
-    pyWord i;
-    pyReal s = 0.0;
-
-    for(i = 0; i < size ; i ++) {
-        s += a[i] * b[i];
-    }
-
-    return s;
-}
-
-pyReal vecNorm(const pyWord size, const pyReal * a) {
-    pyWord i;
-    pyReal s = 0.0;
-
-    for(i = 0; i < size ; i ++) {
-        s += a[i] * a[i];
-    }
-
-    return sqrt(s);
-}
-
-pyReal vecDistSquared(const pyWord size, const pyReal * a, const pyReal * b) {
-    pyWord i;
-    pyReal s = 0.0, d;
-
-    for(i = 0; i < size ; i ++) {
-        d = a[i] - b[i]
-        s += d * d;
-    }
-
-    return s;
-}
-
-void vecSubst(const pyWord size, pyReal * dst, const pyReal * a, const pyReal * b ) {
-    pyWord i;
-    for(i = 0; i < size ; i ++) {
-        dst[i] = a[i] - b[i];
-    }
-}
-
-void vecScale(const pyWord size, pyReal * dst, pyReal s, const pyReal * a) {
-    pyWord i;
-    for(i = 0; i < size ; i ++) {
-        dst[i] = s * a[i];
-    }
-}

+ 0 - 12
library/c/LinAlgebra.h

@@ -1,12 +0,0 @@
-#ifndef _LIN_ALGEBRA_H_
-#define _LIN_ALGEBRA_H_
-
-#include "types.h"
-
-pyReal vecScalarProduct(const pyWord size, const pyReal * a, const pyReal * b);
-pyReal vecNorm(const pyWord size, const pyReal * a);
-pyReal vecDistSquared(const pyWord size, const pyReal * a, const pyReal * b);
-void vecSubst(const pyWord size, pyReal * dst, const pyReal * a, const pyReal * b );
-
-
-#endif

+ 0 - 11
library/c/Makefile

@@ -1,11 +0,0 @@
-c_files = Neighborhood.c utils.c MaxHeap.c
-h_files = Neighborhood.h utils.h MaxHeap.h types.h
-
-
-libNeighborhood.so: $(c_files) $(h_files)
-	gcc -shared -Wall -O2 $(c_files) -o $@
-
-
-test: test.c $(c_files)
-	gcc -Wall -O2 $< -o test.exe -DDoTest
-	./test.exe

+ 0 - 61
library/c/MaxHeap.c

@@ -1,61 +0,0 @@
-#include "MaxHeap.h"
-
-static inline void setItem(MaxHeap * heap, const pyWord pos, const pyWord x, const pyWord d) {
-    heap->indices[pos] = x;
-    heap->distances[pos] = d;
-}
-
-static inline void copyItem(MaxHeap * heap, const pyWord dst, const pyWord src) {
-    heap->indices[dst] = heap->indices[src];
-    heap->distances[dst] = heap->distances[src];
-}
-
-
-void maxHeap_insert(MaxHeap * heap, const pyWord id, const pyReal distance) {
-    if(!heap || heap->maxItems <= 0) {
-        return;
-    }
-
-    if(heap->size < heap->maxItems) {
-        pyWord pos = heap->size;
-        heap->size ++;
-        setItem(heap, pos, id, distance);
-        while(pos > 0) {
-            const pyWord p = pos / 2;
-            if (heap->distances[p] >= heap->distances[pos]) {
-                break;
-            }
-            copyItem(heap, pos, p);
-            pos = p;
-            setItem(heap, pos, id, distance);
-        }
-        return;
-    }
-
-    if(distance > heap->distances[0]) {
-        return;
-    }
-
-    setItem(heap, 0, id, distance);
-
-    pyWord pos = 0;
-    while(pos < heap->size) {
-        const pyWord right = (pos + 1) * 2;
-        const pyWord left = right - 1;
-
-        if(left >= heap->size) {
-            break;
-        }
-
-        const pyWord v = (right >= heap->size || heap->distances[right] < heap->distances[left]) ? left : right;
-
-        if(distance >= heap->distances[v]) {
-            break;
-        }
-
-        copyItem(heap, pos, v);
-        setItem(heap, v, id, distance);
-        pos = v;
-    }
-}
-

+ 0 - 8
library/c/MaxHeap.h

@@ -1,8 +0,0 @@
-#ifndef _MAX_HEAP_H_
-#define _MAX_HEAP_H_
-
-#include "types.h"
-
-void maxHeap_insert(MaxHeap * heap, const pyWord id, const pyReal distance);
-
-#endif

+ 0 - 46
library/c/Neighborhood.c

@@ -1,46 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include "MaxHeap.h"
-#include "utils.h"
-
-#define Point(i)    (&(params->data[i * params->nFeatures]))
-
-
-void nbhSearchBruteForce(SearchParams * params) {
-    pyWord i, j;
-    pyReal d;
-
-    // Berechne alle Distanzen
-    for(i = 0; i < params->nPoints; i ++) {
-        const pyReal *x = Point(i);
-        
-        for(j = i + 1; j < params->nPoints; j ++) {
-            const pyReal * y = Point(j);
-            d = distSquared(x, y, params->nFeatures);
-            
-            maxHeap_insert(&(params->nbhHeaps.heaps[i]), j, d);
-            maxHeap_insert(&(params->nbhHeaps.heaps[j]), i, d);
-        }
-    }
-}
-
-
-void Neighborhood(const pyWord nbhSize, const pyWord nPoints, const pyWord nFeatures, const pyReal * data, pyWord * neighborhoods) {
-    SearchParams params = {
-        .nbhSize = nbhSize,
-        .nPoints = nPoints,
-        .nFeatures = nFeatures,
-        .data = data,
-        .neighborhoods = neighborhoods
-    };
-
-    if(initNbhHeaps(&params)) {
-        return;
-    }
-
-    nbhSearchBruteForce(&params);
-    
-    freeNbhHeaps(&params);
-}
-
-

+ 0 - 10
library/c/Neighborhood.h

@@ -1,10 +0,0 @@
-#ifndef _UTILS_H_
-#define _UTILS_H_
-
-#include "types.h"
-
-void nbhSearchBruteForce(SearchParams * params);
-
-void Neighborhood(const pyWord nbhSize, const pyWord nPoints, const pyWord nFeatures, const pyReal * data, pyWord * neighborhoods);
-
-#endif

BIN
library/c/libNeighborhood.so


+ 0 - 72
library/c/test.c

@@ -1,72 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "Neighborhood.h"
-#include "MaxHeap.h"
-
-
-
-#ifdef DoTest
-void printHeap(const MaxHeap * heap) {
-    pyWord p;
-
-    printf("%u / %u\n", (unsigned int)heap->size, (unsigned int)heap->maxItems);
-    for(p = 0; p < heap->size; p ++) {
-        printf("[%u] %u -> %lf\n", (unsigned int) p, (unsigned int)heap->indices[p], heap->distances[p]);
-    }
-}
-
-
-int main(void) {
-#define testcases 5
-    pyReal distances[testcases];
-    pyWord idxs[testcases];
-    MaxHeap heap = {
-        .distances = distances,
-        .indices = idxs,
-        .maxItems = testcases,
-        .size = 1
-    };
-
-    distances[0] = 0.0;
-    idxs[0] = 999;
-
-    printHeap(&heap);
-    maxHeap_insert(&heap, 6, 6.0);
-    maxHeap_insert(&heap, 1, 1.0);
-    maxHeap_insert(&heap, 4, 4.0);
-    maxHeap_insert(&heap, 3, 3.0);
-    maxHeap_insert(&heap, 2, 2.0);
-    maxHeap_insert(&heap, 5, 5.0);
-    printHeap(&heap);
-
-
-
-#define nPoints 9
-#define nbhSize 5
-    pyWord nbh[nPoints * nbhSize];
-    pyReal points[2 * nPoints];
-    int x, y, p;
-    p = 0;
-    for(y = 0; y < 3 ; y ++) {
-        for(x = 0; x < 3 ; x ++) {
-            points[p] = x;
-            points[p + 1] = y;
-            printf("%d: (%d,%d)\n", p/2, x, y);
-            p += 2;
-        }
-    }
-
-    Neighborhood(nbhSize, nPoints, 2, points, nbh);
-    for(y = 0; y < nPoints; y++) {
-        pyWord * p = &nbh[y * nbhSize];
-        printf("%d [%d,%d] ", y, y % 3, y / 3);
-        for(x = 0; x < nbhSize ; x ++) {
-            printf(" (%u|%u,%u)", (unsigned int)p[x], (unsigned int)(p[x] % 3), (unsigned int)(p[x] / 3));
-        }
-        printf("\n");
-    }
-}
-#endif
-
-

+ 0 - 28
library/c/types.h

@@ -1,28 +0,0 @@
-#ifndef _TYPES_H_
-#define _TYPES_H_
-
-typedef unsigned long long pyWord;
-typedef double pyReal;
-
-typedef struct s_MaxHeap {
-    pyReal * distances;
-    pyWord * indices;
-    pyWord maxItems;
-    pyWord size;
-} MaxHeap;
-
-typedef struct s_NbhHeaps {
-    MaxHeap * heaps;
-    pyReal * distances;
-} NbhHeaps;
-
-typedef struct s_SearchParams {
-    const pyWord nbhSize;
-    const pyWord nPoints;
-    const pyWord nFeatures;
-    const pyReal * data;
-    pyWord * neighborhoods;
-    NbhHeaps nbhHeaps;
-} SearchParams;
-
-#endif

+ 0 - 73
library/c/utils.c

@@ -1,73 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include "utils.h"
-
-
-pyReal distSquared(const pyReal * u, const pyReal * v, const pyWord nFeatures) {
-    pyWord n;
-    pyReal s = 0.0, t;
-    
-    for( n = 0 ; n < nFeatures ; n ++) {
-        t = u[n] - v[n];
-        s += t * t;
-    }
-    
-    return s;
-}
-
-
-void freeNbhHeaps(SearchParams * params) {
-    if(params->nbhHeaps.heaps) {
-       free(params->nbhHeaps.heaps);
-        params->nbhHeaps.heaps = NULL;
-    }
-    
-    if(params->nbhHeaps.distances) {
-        free(params->nbhHeaps.distances);
-        params->nbhHeaps.distances = NULL;
-    }
-}
-
-
-int initNbhHeaps(SearchParams * params) {
-    pyWord i, j;
-    
-    pyWord * nbhI;
-    pyReal * distsI;
-
-    params->nbhHeaps.heaps = NULL;
-    params->nbhHeaps.distances = NULL;
-
-    params->nbhHeaps.distances = (pyReal*) malloc((params->nPoints + 1) * params->nbhSize * sizeof(pyReal));
-    if(params->nbhHeaps.distances == NULL) {
-        puts("Out of memory!");
-        return 1;
-    }
-
-    params->nbhHeaps.heaps = (MaxHeap*) malloc((params->nPoints + 1) * sizeof(MaxHeap));
-    if(params->nbhHeaps.heaps == NULL) {
-        free(params->nbhHeaps.distances);
-        params->nbhHeaps.distances = NULL;
-        puts("Out of memory!");
-        return 1;
-    }
-    
-    // Initialisiere Distanzen und Nachbarschaften
-    for(i = 0; i < params->nPoints; i ++) {
-        distsI = &(params->nbhHeaps.distances[i * params->nbhSize]);
-        nbhI = &(params->neighborhoods[i * params->nbhSize]);
-        params->nbhHeaps.heaps[i].distances = distsI;
-        params->nbhHeaps.heaps[i].indices = nbhI;
-        params->nbhHeaps.heaps[i].maxItems = params->nbhSize;
-        params->nbhHeaps.heaps[i].size = 1;
-
-        for(j = 0; j < params->nbhSize; j ++) {
-            nbhI[j] = i;
-            distsI[j] = 0.0;
-        }
-    }
-
-    return 0;
-}
-
-

+ 0 - 11
library/c/utils.h

@@ -1,11 +0,0 @@
-#ifndef _UTILS_H_
-#define _UTILS_H_
-
-#include "types.h"
-
-pyReal distSquared(const pyReal * u, const pyReal * v, const pyWord nFeatures);
-
-int initNbhHeaps(SearchParams * params);
-void freeNbhHeaps(SearchParams * params);
-
-#endif

+ 0 - 133
library/generators/GanExamples.py

@@ -1,133 +0,0 @@
-"""
-This module contains some example Generative Adversarial Networks for testing.
-
-The classes StupidToyPointGan and StupidToyListGan are not really Networks. This classes are used
-for testing the interface. Hope your actually GAN will perform better than this two.
-
-The class SimpleGan is a simple standard Generative Adversarial Network.
-"""
-
-
-import numpy as np
-
-from library.interfaces import GanBaseClass
-
-
-class StupidToyPointGan(GanBaseClass):
-    """
-    This is a toy example of a GAN.
-    It repeats the first point of the training-data-set.
-    """
-
-    def __init__(self):
-        """
-        Initializes the class and mark it as untrained.
-        """
-        self.isTrained = False
-        self.exampleItem = None
-
-    def reset(self, _dataSet):
-        """
-        Resets the trained GAN to an random state.
-        """
-        self.isTrained = False
-        self.exampleItem = None
-
-    def train(self, dataSet):
-        """
-        Trains the GAN.
-
-        It stores the first data-point in the training data-set and mark the GAN as trained.
-
-        *dataSet* is a instance of /library.dataset.DataSet/. It contains the training dataset.
-        We are only interested in the class 1.
-        """
-        if dataSet.data1.shape[0] <= 0:
-            raise AttributeError("Train GAN: Expected data class 1 to contain at least one point.")
-
-        self.isTrained = True
-        self.exampleItem = dataSet.data1[0].copy()
-
-    def generateDataPoint(self):
-        """
-        Generates one synthetic data-point by copying the stored data point.
-        """
-        if not self.isTrained:
-            raise ValueError("Try to generate data with untrained GAN.")
-
-        return self.exampleItem
-
-    def generateData(self, numOfSamples=1):
-        """
-        Generates a list of synthetic data-points.
-
-        *numOfSamples* is a integer > 0. It gives the number of new generated samples.
-        """
-        numOfSamples = int(numOfSamples)
-        if numOfSamples < 1:
-            raise AttributeError("Expected numOfSamples to be > 0")
-
-        return np.array([self.generateDataPoint() for _ in range(numOfSamples)])
-
-
-class StupidToyListGan(GanBaseClass):
-    """
-    This is a toy example of a GAN.
-    It repeats the first point of the training-data-set.
-    """
-    def __init__(self, maxListSize=100):
-        self.isTrained = False
-        self.exampleItems = None
-        self.nextIndex = 0
-        self.maxListSize = int(maxListSize)
-        if self.maxListSize < 1:
-            raise AttributeError("Expected maxListSize to be > 0 but got " + str(self.maxListSize))
-
-    def reset(self, _dataSet):
-        """
-        Resets the trained GAN to an random state.
-        """
-        self.isTrained = False
-        self.exampleItems = None
-
-    def train(self, dataSet):
-        """
-        Trains the GAN.
-
-        It stores the first data-point in the training data-set and mark the GAN as trained.
-
-        *dataSet* is a instance of /library.dataset.DataSet/. It contains the training dataset.
-        We are only interested in the first *maxListSize* points in class 1.
-        """
-        if dataSet.data1.shape[0] <= 0:
-            raise AttributeError("Train GAN: Expected data class 1 to contain at least one point.")
-
-        self.isTrained = True
-        self.exampleItems = dataSet.data1[: self.maxListSize].copy()
-
-    def generateDataPoint(self):
-        """
-        Returns one synthetic data point by repeating the stored list.
-        """
-        if not self.isTrained:
-            raise ValueError("Try to generate data with untrained GAN.")
-
-        i = self.nextIndex
-        self.nextIndex += 1
-        if self.nextIndex >= self.exampleItems.shape[0]:
-            self.nextIndex = 0
-
-        return self.exampleItems[i]
-
-
-    def generateData(self, numOfSamples=1):
-        """
-        Generates a list of synthetic data-points.
-
-        *numOfSamples* is a integer > 0. It gives the number of new generated samples.
-        """
-        numOfSamples = int(numOfSamples)
-        if numOfSamples < 1:
-            raise AttributeError("Expected numOfSamples to be > 0")
-
-        return np.array([self.generateDataPoint() for _ in range(numOfSamples)])

+ 0 - 142
library/generators/SpheredNoise.py

@@ -1,142 +0,0 @@
-"""
-This module contains some example Generative Adversarial Networks for testing.
-
-The classes StupidToyPointGan and StupidToyListGan are not really Networks. This classes are used
-for testing the interface. Hope your actually GAN will perform better than this two.
-
-The class SimpleGan is a simple standard Generative Adversarial Network.
-"""
-
-
-import numpy as np
-import math
-
-from library.interfaces import GanBaseClass
-
-def square(x):
-    return (x*x)
-
-def fold0(f, xs):
-    if xs == []:
-        return None
-   
-    s = xs[0]
-    for x in xs[1:]:
-        s = f(s, x)
-    return s
-
-def fold1(f, s0, xs):
-    if xs == []:
-        return None
-   
-    s = s0
-    for x in xs:
-        s = f(s, x)
-    return s
-
-def dist(x, y):
-    return math.sqrt(fold1(lambda s, a: s + square(a[0] - a[1]), 0, list(zip(x, y))))
-
-def minDistPointToSet(x, setB):
-    return fold0(lambda m,y: min(m,y), [dist(x,y) for y in setB])
-
-def minDistSetToSet(setA, setB):
-    return fold0(lambda m,x: min(m, minDistPointToSet(x,setB)), setA)
-
-def normInf(xs):
-    return fold0(lambda m, x: max(m, abs(x)), xs)
-
-def norm2Sq(xs):
-    return fold0(lambda s, x: s + (x*x), xs)
-
-def norm2(xs):
-    return math.sqrt(norm2Sq(xs))
-
-
-def minmax(xs):
-    if xs == []:
-        return None
-   
-    (mi, mx) = (xs[0][1], xs[0][1])
-    for x in xs[1:]:
-        mi = min(mi, x[1])
-        mx = max(mx, x[1])
-    return (mi, mx)
-
-
-def createSquare(pointCount, noiseSize):
-    noise = [
-        [np.random.uniform(-1.0, 1.0) for n in range(noiseSize)]
-        for m in range(pointCount)
-        ]
-    return np.array(noise)
-
-def createDisc(pointCount, noiseSize):
-    noise = []
-    for n in range(pointCount):
-        p = [np.random.uniform(-1.0, 1.0)]
-        for m in range(noiseSize - 1):
-            d = norm2Sq(p)
-            d = math.sqrt(1.0 - d)
-            p.append(np.random.uniform(0.0 - d, d))
-        noise.append(p)
-    return np.array(noise)
-
-class SpheredNoise(GanBaseClass):
-    """
-    A class for a simple GAN.
-    """
-    def __init__(self, noiseSize=101):
-        self.canPredict = False
-        self.isTrained = False
-        self.noiseSize = noiseSize
-        self.disc = []
-        self.reset()
-
-    def reset(self, _dataSet):
-        """
-        Resets the trained GAN to an random state.
-        """
-        self.pointDists = []
-        self.nextId = 0
-        self.numPoints = 0
-        self.nextDiscPoint = 0
-        self.minDist = 0.0
-
-    def train(self, dataset):
-        majoritySet = dataset.data0
-        minoritySet = dataset.data1
-        trainDataSize = minoritySet.shape[0]
-        numOfFeatures = minoritySet.shape[1]
-        
-        print(f"Train {majoritySet.shape[0]}/{trainDataSize} points")
-
-        if minoritySet.shape[0] <= 0 or majoritySet.shape[0] <= 0:
-            raise AttributeError("Train: Expected each data class to contain at least one point.")
-
-        if numOfFeatures <= 0:
-            raise AttributeError("Train: Expected at least one feature.")
-
-        print("-> new disc")
-        self.disc = createDisc(self.noiseSize, minoritySet.shape[1])
-        print("-> calc distances")
-        self.pointDists = list(filter(lambda x: x[1] > 0.0, [(x, minDistPointToSet(x, majoritySet)) for x in minoritySet]))
-        print("-> statistics")
-        self.nextId = 0
-        self.numPoints = len(self.pointDists)
-        self.isTrained = True
-        (minD, maxD) = minmax(self.pointDists)
-        self.minDist = minD
-        print(f"trained {trainDataSize} points min:{minD} max:{maxD}")
-
-    def generateDataPoint(self):
-        (x, d) = self.pointDists[self.nextId]
-        self.nextId = (self.nextId + 1) % self.numPoints
-        disc = (0.5 * self.minDist) * self.disc
-        p = disc[self.nextDiscPoint]
-        self.nextDiscPoint = (self.nextDiscPoint + 1) % disc.shape[0]
-        return p
-
-
-    def generateData(self, numOfSamples=1):
-        return np.array([self.generateDataPoint() for n in range(numOfSamples)])

+ 0 - 3
library/generators/__init__.py

@@ -1,9 +1,6 @@
-from library.generators.autoencoder import Autoencoder
 from library.generators.SimpleGan import SimpleGan
 from library.generators.ConvGeN import ConvGeN
 from library.generators.LoRAS_ProWRAS import ProWRAS
 from library.generators.Repeater import Repeater
-from library.generators.SpheredNoise import SpheredNoise
-from library.generators.GanExamples import StupidToyListGan, StupidToyPointGan
 from library.generators.ctgan import CtGAN
 from library.generators.ctab import CtabGan

+ 0 - 248
library/generators/autoencoder.py

@@ -1,248 +0,0 @@
-import numpy as np
-
-from library.interfaces import GanBaseClass
-from library.dataset import DataSet
-
-from sklearn.decomposition import PCA
-from sklearn.metrics import confusion_matrix
-from sklearn.metrics import f1_score
-from sklearn.metrics import cohen_kappa_score
-from sklearn.metrics import precision_score
-from sklearn.metrics import recall_score
-from sklearn.neighbors import NearestNeighbors
-from sklearn.utils import shuffle
-from imblearn.datasets import fetch_datasets
-
-from keras.layers import Dense, Input, Multiply, Flatten, Conv1D, Reshape
-from keras.models import Model
-from keras import backend as K
-from tqdm import tqdm
-
-import tensorflow as tf
-from tensorflow.keras.optimizers import Adam
-from tensorflow.keras.layers import Lambda
-
-from library.NNSearch import NNSearch
-
-import warnings
-warnings.filterwarnings("ignore")
-
-
-lossFunction = "mean_squared_logarithmic_error"
-#lossFunction = "mse"
-
-
-def newDense(size, activation="relu"):  # softsign
-    initializer = tf.keras.initializers.RandomUniform(minval=0.00001, maxval=float(size))
-    initializer = "glorot_uniform"
-
-    return Dense(int(size)
-        , activation=activation
-        , kernel_initializer=initializer
-        , bias_initializer=initializer
-        )
-
-
-class Autoencoder(GanBaseClass):
-    """
-    This is a toy example of a GAN.
-    It repeats the first point of the training-data-set.
-    """
-    def __init__(self, n_feat, middleSize=4, eps=0.0001, debug=True):
-        self.canPredict = False
-        self.isTrained = False
-        self.n_feat = n_feat
-        self.middleSize = middleSize
-        self.eps = eps
-        self.debug = debug
-        self.dataSet = None
-        self.decoder = None
-        self.encoder = None
-        self.autoencoder = None
-        self.cg = None
-        self.scaler = 1.0
-        self.lossFn = lossFunction #"mse"
-        self.lossFn = "mean_squared_logarithmic_error"
-
-    def reset(self, _dataSet):
-        """
-        Resets the trained GAN to an random state.
-        """
-        self.isTrained = False
-        self.scaler = 1.0
-        ## instanciate discriminator network and visualize architecture
-        self.encoder = self._createEncoder()
-
-        ## instanciate generator network and visualize architecture
-        self.decoder = self._createDecoder()
-
-        ## instanciate network and visualize architecture
-        self.autoencoder = self._createAutoencoder(self.encoder, self.decoder)
-
-    def train(self, dataSet):
-        """
-        Trains the GAN.
-
-        It stores the data points in the training data set and mark as trained.
-
-        *dataSet* is a instance of /library.dataset.DataSet/. It contains the training dataset.
-        We are only interested in the first *maxListSize* points in class 1.
-        """
-        if dataSet.data1.shape[0] <= 0:
-            raise AttributeError("Train: Expected data class 1 to contain at least one point.")
-
-        d = dataSet.data1
-        self.data1 = d
-        self.scaler = 1.5 * tf.reduce_max(tf.abs(d)).numpy()
-        scaleDown = 1.0 / self.scaler
-
-        lastLoss = 0.0
-        print(f"scaler: {self.scaler}")
-
-        dScaled = scaleDown * d
-        
-        for epoch in range(1000):
-            h = self.autoencoder.fit(d, dScaled, epochs=1, shuffle=True)
-            #print(str(d[0]) + " →")
-            #print(self.scaler * self.autoencoder.predict(np.array([d[0]])))
-            loss = h.history["loss"][-1]
-            if loss < self.eps:
-                print(f"done in {epoch} rounds")
-                break
-
-            if epoch == 0:
-                lastLoss = loss
-            else:
-                print(f"Loss: {lastLoss} → {loss}")
-                if abs(lastLoss - loss) < (0.1 * self.eps) and epoch > 10:
-                    print(f"converged in {epoch} rounds")
-                    break
-                else:
-                    lastLoss = loss
-
-
-        code = self.encoder.predict(d)
-        center = np.zeros(self.middleSize)
-        for c in code:
-            center = center + c
-        center = (1.0 / float(d.shape[0])) * center
-
-        d = 0.0
-        for c in code:
-            d = max(d, tf.reduce_max(tf.abs(c - center)).numpy())
-
-        self.noise = (center, d)
-
-        self.isTrained = True
-
-    def generateDataPoint(self):
-        """
-        Returns one synthetic data point by repeating the stored list.
-        """
-        return (self.generateData(1))[0]
-
-
-    def generateData(self, numOfSamples=1):
-        """
-        Generates a list of synthetic data-points.
-
-        *numOfSamples* is a integer > 0. It gives the number of new generated samples.
-        """
-        if not self.isTrained:
-            raise ValueError("Try to generate data with untrained Re.")
-
-        noise = self.noise[0] + np.random.normal(0.0, self.noise[1], [numOfSamples, self.middleSize])
-        syntheticPoints = self.decoder.predict(noise)
-        
-        # syntheticPoints = []
-        # while len(syntheticPoints) < numOfSamples:
-        #     nRest = max(0, numOfSamples - len(syntheticPoints))
-        #     nBatch = min(nRest, len(self.data1))
-        #     syntheticPoints.extend(self.autoencoder.predict(self.data1[:nBatch]))
-
-        return self.scaler * np.array(syntheticPoints)
-
-    # ###############################################################
-    # Hidden internal functions
-    # ###############################################################
-
-    # Creating the GAN
-    def _createEncoder(self):
-        """
-        the generator network to generate synthetic samples from the convex space
-        of arbitrary minority neighbourhoods
-        """
-
-        ## takes minority batch as input
-        dataIn = Input(shape=(self.n_feat,))
-        x = dataIn
-        x = newDense(self.n_feat)(x)
-
-        ## 
-        n = self.n_feat // 2
-        x = newDense(max(n, self.middleSize))(x)
-
-        x = newDense(self.middleSize)(x)
-
-        model = Model(inputs=dataIn, outputs=x)
-        opt = Adam(learning_rate=0.01)
-        model.compile(loss=lossFunction, optimizer=opt)
-
-        print("encoder")
-        model.summary()
-        return model
-
-    def _createDecoder(self):
-        """
-        the generator network to generate synthetic samples from the convex space
-        of arbitrary minority neighbourhoods
-        """
-
-        ## takes minority batch as input
-        dataIn = Input(shape=(self.middleSize,))
-        x = dataIn
-
-        ## 
-        n = self.n_feat // 2
-        #x = newDense(max(n, self.middleSize))(x)
-
-        #x = newDense(self.n_feat)(x)
-        x = newDense(self.n_feat)(x)
-
-        model = Model(inputs=dataIn, outputs=x)
-        opt = Adam(learning_rate=0.01)
-        model.compile(loss=lossFunction, optimizer=opt)
-
-        print("decoder")
-        model.summary()
-        return model
-
-
-    def _createAutoencoder(self, encoder, decoder):
-        """
-        for joining the generator and the discriminator
-        conv_coeff_generator-> generator network instance
-        maj_min_discriminator -> discriminator network instance
-        """
-
-        #encoder.trainable = False
-        ## input receives a neighbourhood minority batch
-        ## and a proximal majority batch concatenated
-        dataIn = Input(shape=(self.n_feat,))
-        #x = newDense(self.middleSize)(dataIn)
-        #x = newDense(self.n_feat)(x)
-        #x = newDense(self.n_feat)(x)
-        
-        x = encoder(dataIn )
-        x = decoder(x)
-
-        ## note that, the discriminator will not be traied but will make decisions based
-        ## on its previous training while using this function
-        model = Model(inputs=dataIn, outputs=x)
-        opt = Adam(learning_rate=0.01)
-        model.compile(loss=self.lossFn, optimizer=opt)
-
-        print("autoencoder")
-        model.summary()
-        return model
-