3

I am using Skfuzzy to interpret two arrays: 1. distances to a stream [dist]; 2. Strahler order[order]. I then want to calculate the consequent (a vulnerability value) for each stream distance and Strahler order pairs using a set of custom membership values I have created for the antecedents and consequent. I have the program working for a single input of values, but I don't understand how to get skfuzzy to loop through an array of input values and output the consequent for each value pair.

The control system:

# Creation of control system using the defined rules
    vulnerability_ctrl = ctrl.ControlSystem([rule1, rule2, rule3])
    vulnerability = ctrl.ControlSystemSimulation(vulnerability_ctrl)

The inputs and computation:

# input of distance and Strahler order arrays
    vulnerability.input[dist]
    vulnerability.input[order]
    vulnerability.compute()

I get this error because I don't know how skfuzzy deals with an array of inputs:

TypeError: '_InputAcceptor' object is not subscriptable
GEobserver
  • 53
  • 5

1 Answers1

1

One can iterate down an array through the use of a for loop as shown below. First ensure that your array is converted to float type using 'numpy.asfarray'.

# Convert to float array
    dist_x = np.asfarray(strm_dist)
    order_x = np.asfarray(strm_order)

# iterate down an array of input values
    strm_vul = []
    for i in range(len(dist)):
        vulnerability.input['dist'] = dist_x[i]
        vulnerability.input['order'] = order_x[i]
        vulnerability.compute()
        strm_vul.append(vulnerability.output['vul'])
GEobserver
  • 53
  • 5