def calculateProbabilityImpreciseKernel(dataset, h, epsilon, N):
	# TRIER LES DONNEES DU DATASET ET ENSUITE MAJ LA SOMME A CHAQUE ITERATION :)
	# sortedDataset = sorted(dataset)
	n = len(dataset)
	# print('n=', n)
	stepLinspace = 0.05  # ATTENTION Mettre au moins 0.05 pours les vrai tests !

	lowProbabilities = []
	hightProbabilities = []
	# print('DATASET AVANT PASSAGE DANS KERNEL :', dataset)
	tKernelTri = KernelContext(dataset, TriangularKernel(h), stepLinspace)

	for pt in tKernelTri.domain:
		# Def des structures qui vont récolter les données (dans la boucle pour une remise à 0 à chaque cycle
		# lenDomain.append(len(tKernelTri.domain))

		structHMin = {'potentialHValue': -1, 'minValue': -1}

		structHMax = {'potentialHValue': -1, 'maxedValue': -1}

		# Calculs de f(hMax), et f(hMin)
		structHMax = tKernelTri.computeHMaxFromInterval(pt, h, epsilon)
		structHMin = tKernelTri.computeHMinFromInterval(pt, h, epsilon)

		hightProbabilities.append(structHMax['maxedValue'])
		lowProbabilities.append(structHMin['minValue'])

	# print('Hight probability = ', hightProbability)
	return lowProbabilities, hightProbabilities, tKernelTri.domain
from classes.SampleGenerator.MultimodalGenerator import MultimodalGenerator
from classes.KernelContext import KernelContext

SEED = 1245632214124  #598473 # SUPER SEED ICI 157  #47 #53 # 23
random.seed(SEED)
experimentalSample = []
centerPoint = 5
for i in range(0, 10):
    appending = False
    while appending == False:
        tirAlea = random.randint(0, 20)
        if tirAlea != centerPoint:
            appending = True
            experimentalSample.append(tirAlea)

tKernel2 = TriangularKernel(0.1)

#test = TriangularKernel.testUnitaires()

#print(test)

if 0 == 0:

    dist2 = []
    extremizer = KernelContext(experimentalSample, tKernel2)
    maxStruct = extremizer.computeHMax(centerPoint)

    distances = []
    for ind, i in enumerate(experimentalSample):
        distance = abs(i - centerPoint)
        plt.axvline(x=distance * 2, color='red')
示例#3
0
from statistics import stdev

from classes.Kernels.TriangularKernel import TriangularKernel
from classes.KernelContext import KernelContext
from classes.SampleGenerator.MultimodalGenerator import MultimodalGenerator
"""Génération de la multimodale de test (faite à la main)"""
sampleTestUni = [2, 2.62, 2.84, 2.95, 4.3, 4.7, 4.97, 5.31, 5.7, 7]
"""Déclaration des structures devant contenir le min et le max de h et de f(h)"""
maxStruct = {'potentialHValue': -1, 'maxedValue': -1}

maxStructFromInt_1 = {'potentialHValue': -1, 'minValue': -1}

minStructFromInt_1 = {'potentialHValue': -1, 'minValue': -1}
"""Déclaraiton du Kernel utilisé """

TKernel = KernelContext(sampleTestUni, TriangularKernel(0.1), 1)
"""Définition des matrices des résultats"""

# ComputeHMax
WaitedHMaxResults_0 = [[8.478, .058976174], [6.478, .077184316],
                       [1.205, 0.16975104], [.1, .5],
                       [2.348888889, 0.19157943], [.06, .8333333333],
                       [2.006666666666, .149501661], [5.522, .090546903],
                       [7.522, .066471683], [9.522, .052509977]]

# ComputeHMax/MinFromIntervalle avec h=2 et eps = 0.5
WaitedHMaxResults_1 = [[2.5, .008], [2.5, .05744], [1.5, 0.15955555],
                       [1.5, .2048888889], [2.348888889, 0.19157943],
                       [1.5, .24266666], [2.006666666666, .149501661],
                       [2.5, .08288], [2.5, .0272], [2.5, 0.008]]
sample = MultimodalGenerator([(nbPointsFirstGauss,-1,1),(nbPointsSecondGauss,5,2)]).generateNormalSamples()

# Def du hOpt

sigma=stdev(sample)

hOpt = 1.06*sigma*(nbPointsFirstGauss+nbPointsSecondGauss)**(-1/5)
#print("hopt",hOpt)

# Def epsilon

#epsilon = 0.2*hOpt   #mettre ce paramettre en fonction du hOpt trouvé.


#def Kernel
tKernelTri = KernelContext(sample,TriangularKernel(hOpt),stepLinspace)

# Def des tableau qui vont stocker les valeurs des f(hMax), f(hOpt) et f(hMin)
for epsilon in (hOpt*.05, hOpt*.1, hOpt*.2, hOpt*.4, hOpt*.6, hOpt*.9):
    if epsilon < hOpt*.1 :
        yTriHOptOnDomain = []
    yTriHMaxOnDomain = []
    yTriHMinOnDomain = []

    yInitialBimodal  = []

    lenDomain=[]

    for pt in tKernelTri.domain:
        # Def des structures qui vont récolter les données (dans la boucle pour une remise à 0 à chaque cycle
        lenDomain.append(len(tKernelTri.domain))
示例#5
0
from classes.Kernels.TriangularKernel import TriangularKernel
from classes.Kernels.EllipseKernel import EllipseKernel
from classes.SampleGenerator.MultimodalGenerator import MultimodalGenerator
from classes.KernelContext import KernelContext

from math import sqrt
from math import pi

hTestTri = 3
hTestEll = 2 * sqrt(pi)
"""valeur qui nous permet d'être proche à 10^-precis près du premier point en dehors de [x-hTest/2 ; x+hTest/2]"""
precis = 6
sample = MultimodalGenerator([(100, -1, 1),
                              (400, 5, 2)]).generateNormalSamples()
tKernelTri = TriangularKernel(hTestTri)
tKernelEll = EllipseKernel(hTestEll)
defDomain = np.linspace(-4, 12, 200)
yTriOnDomain = []
yTriHMinOnDomain = []
yTriHMaxOnDomain = []
yEllOnDomain = []
yEllHMinOnDomain = []
yEllHMaxOnDomain = []
"""
    TEST CODE PIERRE
"""

kc = KernelContext(sample, tKernelTri)
ftest, domain_test = kc.computeTotalDensity()
maxstru = kc.computeHMax(5)