Simple Python implementation of the Weiszfeld algorithm

March 14, 2021
machine_learning python weiszfeld_algorithm

Following is a simple implementation of the Weiszfeld algortihm that was discussed in a previous post in python.

import numpy as np
import math
from numpy import array

def weiszfeld(points):

    max_error = 0.0000000001

    x=np.array([point[0] for point in  points])
    y=np.array([point[1] for point in  points])


    ext_condition = True

    start_x = np.average(x)
    start_y = np.average(y)

    while ext_condition:

        sod = (((x - start_x)**2) + ((y - start_y)**2))**0.5

        new_x = sum(x/sod) / sum(1/sod)
        new_y = sum(y/sod) / sum(1/sod)

        ext_condition = (abs(new_x - start_x) > max_error) or 
            (abs(new_y - start_y) > max_error)

        start_y = new_y
        start_x = new_x

        print(new_x, new_y)


if __name__=="__main__":
    weiszfeld([(2,1), (12,2), (3,9), (13,11)])

Type2Fuzzy Library Implementation: Mendel, Jerry M., and RI Bob John. 'Type-2 fuzzy sets made simple.'

October 27, 2021
type2_fuzzy type2_fuzzy_library fuzzy python

Mathematical prerequisites for some Clustering techniques

October 14, 2021
maths machine_learning

Notes on Monte Carlo Simulation

March 14, 2021
machine_learning python random_walk
comments powered by Disqus
hugo_cms 11 fuzzy 10 python 9 machine_learning 5 type2_fuzzy_library 5 cnc 4 type1_fuzzy 4 type2_fuzzy 4 r 3 excel 2 iot 2 it2fs 2 weiszfeld_algorithm 2 arduino 1 classifier 1 development 1 game 1 javascript 1 learning 1 mathjax 1 maths 1 mxchip 1 pandas 1 random_walk 1 robot 1 roc 1 set 1 tools 1 type_2_fuzzy 1 vscode 1 wsl 1