vendredi 22 janvier 2021

random selection, probabilistic placement

Apologies if this has been asked somewhere, but I cannot find anything that suits my case.

I have two lists, X and Y, of equal length. I have a third list, locations. The values in X and Y are related to the indexes of the list locations. I also have an equation, which is below.

def equat(x):
        return np.power(x, -0.0005165876209672664) - 0.9960910063226581

Below is the main for loop for my problem.

for i, j in zip(X[:10], Y[:10]):
        A = np.random.choice(X, replace = False) # randomly select neuron from neuron A
        L_a = locations.iloc[[A],] # acquire neuron A's location
        L_b = locations.iloc[[j],] # acquire neuron B's location (unchanged from list)
        D_ = pd.DataFrame(scipy.spatial.distance.cdist(L_a, L_b, 'euclidean')) # compute its distance

First up, I have lists X and Y. A selects randomly from list X. L_a then uses the value A to obtain the location of this value. L_b uses the first value in Y, since as mentioned before, list Y must remain unchanged throughout. D_ will then compute the distance between the L_a and L_b.

Now, this is where I am kinda stuck. What I would like to do is to, first of all make sure that the two points are not the same, and if they are, to go back to A and randomly select another value from the list. Secondly, I would like to add the value of A that was selected to be added to a list, say C, based on a probability which is generated by the use of equat. If this match does not happen, then I would like the loop to go back through to A and randomly select another value until the value is selected and added to C.

Any advice on how to go about this would be greatly received!

Thanks




Aucun commentaire:

Enregistrer un commentaire