0% found this document useful (0 votes)
17 views8 pages

Untitled 25

Uploaded by

Amnah Aziza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

Untitled 25

Uploaded by

Amnah Aziza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

5/2/24, 12:51 AM Untitled25 (2)

Fuzzification

Input Membership Function


In [ ]: import pandas as pd
import numpy as np

# Coefficients for Type 1 CFIS


a1 = 1.000 + 0.600j
a1_2= 0.6j
a2 = 0.100j
a2_2 = 0.100 - 0.500j
a3 = 0.800 - 0.600j
a4 = 3.200 - 1.400j
a4_2 = -2.200 + 1.600j
a3_2 = -0.100
a5 = 13.100 + 7.000j
a5_2 = -8.8 -9.6j
a6 = 0.600 + 0.100j
a6_1 = 0
a6_2 = 0
# Define the input membership function for Type 1 CFIS
def type_2_membership_function(x, a1,a2, L):

return (a1 * x + a2 * x**2) / L


# Define the input membership function for the superplasticizer input variable
def superplasticizer_membership_function(x, a0, a1, a2, L):

return (a0 + a1 * x + a2 * x**2) / L


# Load data from CSV file
data = pd.read_csv("slump_test.data")

# Extract input variables from the data


x1 = data['Cement'] / data['Water']
x2 = data['Slag'] / data['Water']
x3 = data['Fly ash'] / data['Water']
x4 = data['Coarse Aggr.'] * 0.001
x5 = data['Fine Aggr.'] * 0.001
x6 = data['SP']

# Compute L for each row (maximum of x1, x2, x3, x4, x5, x6)
L = np.maximum.reduce([x1, x2, x3,
x4, x5, x6], axis=0)

# Compute membership values for each input variable


membership_values_x1 = type_2_membership_function(x1, a1, a1_2, L_values)
membership_values_x2 = type_2_membership_function(x2, a2,a2_2, L_values)
membership_values_x3 = type_2_membership_function(x3, a3,a3_2, L_values)
membership_values_x4 = type_2_membership_function(x4, a4,a4_2, L_values)
membership_values_x5 = type_2_membership_function(x5, a5, a5_2, L_values)
membership_values_x6 = superplasticizer_membership_function(x6, a6,a6_1,a6_2, L_

# Print the computed membership values


print("Membership values for x1:")

file:///C:/Users/Dell/Downloads/Untitled25 (2).html 1/8


5/2/24, 12:51 AM Untitled25 (2)

print(membership_values_x1)
print("\nMembership values for x2:")
print(membership_values_x2)
print("\nMembership values for x3:")
print(membership_values_x3)
print("\nMembership values for x4:")
print(membership_values_x4)
print("\nMembership values for x5:")
print(membership_values_x5)
print("\nMembership values for x6:")
print(membership_values_x6)

file:///C:/Users/Dell/Downloads/Untitled25 (2).html 2/8


5/2/24, 12:51 AM Untitled25 (2)

Membership values for x1:


0 0.144444+0.199333j
1 0.075463+0.086279j
2 0.056564+0.064654j
3 0.047633+0.054445j
4 0.070000+0.071400j
...
98 0.190922+0.282958j
99 0.190466+0.281881j
100 0.194253+0.288621j
101 0.204192+0.310141j
102 0.174211+0.279339j
Length: 103, dtype: complex128

Membership values for x2:


0 0.001694-0.004132j
1 0.005710-0.021653j
2 0.004273-0.016196j
3 0.003598-0.013638j
4 0.002592-0.007868j
...
98 0.004644-0.015454j
99 0.004633-0.015408j
100 0.003316-0.009974j
101 0.000593-0.000152j
102 0.000000+0.000005j
Length: 103, dtype: complex128

Membership values for x3:


0 0.041667-0.033333j
1 0.061358-0.053056j
2 0.046236-0.040014j
3 0.038763-0.033520j
4 0.048079-0.039273j
...
98 0.121052-0.110309j
99 0.121257-0.110547j
100 0.119293-0.107905j
101 0.111515-0.098928j
102 0.077242-0.066876j
Length: 103, dtype: complex128

Membership values for x4:


0 0.121658+0.004661j
1 0.094514-0.003597j
2 0.070980-0.002940j
3 0.059824-0.002611j
4 0.107936+0.007089j
...
98 0.136408+0.015703j
99 0.136961+0.014784j
100 0.140146+0.012631j
101 0.145475+0.006573j
102 0.120416-0.011636j
Name: Coarse Aggr., Length: 103, dtype: complex128

Membership values for x5:


0 0.537653+0.035662j
1 0.406272-0.010046j
2 0.304704-0.006167j

file:///C:/Users/Dell/Downloads/Untitled25 (2).html 3/8


5/2/24, 12:51 AM Untitled25 (2)

3 0.256589-0.004430j
4 0.480972+0.044955j
...
98 0.620860+0.070736j
99 0.621675+0.068311j
100 0.630292+0.067864j
101 0.639995+0.064547j
102 0.507668-0.021934j
Name: Fine Aggr., Length: 103, dtype: complex128

Membership values for x6:


0 0.066667+0.011111j
1 0.050000+0.008333j
2 0.037500+0.006250j
3 0.031579+0.005263j
4 0.060000+0.010000j
...
98 0.077922+0.012987j
99 0.077922+0.012987j
100 0.078947+0.013158j
101 0.080000+0.013333j
102 0.062500+0.010417j
Name: SP, Length: 103, dtype: complex128

Output Membership Function


In [ ]: # Define the output membership functions
def output_membership_function_P(k):

if k >= 0:
return k / (1 + k)
else:
return 0

def output_membership_function_N(k):

if k >= 0:
return 0
else:
return -k / (1 - k)

# Example usage:
# Extract output variable (comprehensive strength) from the data
k = data['Compressive Strength (28-day)(Mpa)']

membership_values_P = k.apply(output_membership_function_P)
membership_values_N = k.apply(output_membership_function_N)

# Print the computed membership values


print("Membership values for P output:")
print(membership_values_P)

print("\nMembership values for N output:")


print(membership_values_N)

file:///C:/Users/Dell/Downloads/Untitled25 (2).html 4/8


5/2/24, 12:51 AM Untitled25 (2)

Membership values for P output:


0 0.972215
1 0.976270
2 0.976641
3 0.976787
4 0.964055
...
98 0.980381
99 0.980480
100 0.980583
101 0.980068
102 0.979908
Name: Compressive Strength (28-day)(Mpa), Length: 103, dtype: float64

Membership values for N output:


0 0
1 0
2 0
3 0
4 0
..
98 0
99 0
100 0
101 0
102 0
Name: Compressive Strength (28-day)(Mpa), Length: 103, dtype: int64

In [ ]: import pandas as pd
# Load data from CSV file
data = pd.read_csv("slump_test.data")
# Define the fuzzy rules for the concrete mixing dataset
def rule_CFR1(x1, x6):
if x1 > 0 and x6 > 0:
return 'P' # High firing strength
else:
return 'N' # Low firing strength
def rule_CFR2(x2, x6):
if x2 > 0 and x6 > 0:
return 'P'
else:
return 'N'
def rule_CFR3(x3, x6):
if x3 > 0 and x6 > 0:
return 'P'
else:
return 'N'
def rule_CFR4(x4):
if x4 > 0:
return 'P'
else:
return 'N'
def rule_CFR5(x5):
if x5 > 0:
return 'P'
else:
return 'N'
# Compute the firing strengths using the defined rules
data['Firing Strength CFR1'] = data.apply(lambda row: rule_CFR1(row['Cement'] /
data['Firing Strength CFR2'] = data.apply(lambda row: rule_CFR2(row['Slag'] / ro

file:///C:/Users/Dell/Downloads/Untitled25 (2).html 5/8


5/2/24, 12:51 AM Untitled25 (2)

data['Firing Strength CFR3'] = data.apply(lambda row: rule_CFR3(row['Fly ash'] /


data['Firing Strength CFR4'] = data.apply(lambda row: rule_CFR4(row['Coarse Aggr
data['Firing Strength CFR5'] = data.apply(lambda row: rule_CFR5(row['Fine Aggr.'

In [ ]: import pandas as pd
# Compute firing strength for each rule
firing_R1 = x1 * x6
firing_R2 = x2 * x6
firing_R3 = x3 * x6
firing_R4 = membership_values_x4
firing_R5 = membership_values_x5
# Aggregate the firing strengths using multiplication
aggregated_firing_strength = firing_R1 * firing_R2 * firing_R3 * firing_R4 * fir
# Add the aggregated firing strength to the dataset
data['Aggregated Firing Strength'] = aggregated_firing_strength
print(aggregated_firing_strength)

0 1.130417e-09-3.655288e-10j
1 7.689922e-10-7.036447e-10j
2 7.726641e-11-7.060704e-11j
3 1.948422e-11-1.776389e-11j
4 5.341231e-10-2.835097e-10j
...
98 3.625427e-08-1.189926e-08j
99 3.610162e-08-1.232353e-08j
100 2.558365e-08-8.313134e-09j
101 1.344543e-09+1.027889e-09j
102 -1.596983e-12+2.078968e-12j
Length: 103, dtype: complex128

In [ ]: # Define the output membership functions


def output_function_P(k):

if k >= 0:
return k / (1 + k)
else:
return 0

def output_function_N(k):

if k >= 0:
return 0
else:
return -k / (1 - k)
# Extract output variable (comprehensive strength) from the data
comprehensive_strength = data['Compressive Strength (28-day)(Mpa)']
# Iterate through each value in the Series and apply the output membership funct
membership_values_P = comprehensive_strength.apply(output_function_P)
membership_values_N = comprehensive_strength.apply(output_function_N)
firing_R1 = x1 * x6
firing_R2 = x2 * x6
firing_R3 = x3 * x6
firing_R4 = membership_values_x4
firing_R5 = membership_values_x5
# Compute consequent functions by multiplying firing strength with output member
CFR1 = firing_R1 * membership_values_P
CFR2 = firing_R2 * membership_values_P
CFR3 = firing_R3 * membership_values_P
CFR4 = firing_R4 * membership_values_P
CFR5 = firing_R5 * membership_values_P

file:///C:/Users/Dell/Downloads/Untitled25 (2).html 6/8


5/2/24, 12:51 AM Untitled25 (2)

# Aggregate consequent functions by taking the sum


aggregated_consequent_P = (CFR1 + CFR2 +CFR3 + CFR4 +CFR5)
# Print the aggregated consequent functions
print("Aggregated Consequent Function ")
print(aggregated_consequent_P)

Aggregated Consequent Function


0 19.807507+0.039202j
1 33.226475-0.013319j
2 44.102965-0.008894j
3 52.149739-0.006878j
4 18.534212+0.050172j
...
98 27.040758+0.084743j
99 27.036062+0.081473j
100 25.684761+0.078932j
101 22.665992+0.069703j
102 26.418475-0.032896j
Length: 103, dtype: complex128

In [ ]: from re import L
# Calculate the limits of the aggregated consequent functions
limit_positive = aggregated_consequent_P.iloc[-1] # Limit as k approaches posit
limit_negative = 0
# Calculate k0
k0 = L * (limit_positive - limit_negative)

In [ ]: k1 = np.square(k0)
defuzzified_output = abs(k1)

In [ ]: # Print the predicted comprehensive strength


print("Defuzzified Output: ", defuzzified_output)

Defuzzified Output: [35.52726686 31.04722687 39.81313333 41.0579 33.41344787


35.52726686
39.8987 36.34826188 36.34826188 36.34826188 33.41344787 37.51632329
36.34826188 36.34826188 37.51632329 36.16080333 36.34826188 31.71922192
33.41344787 35.52726686 33.41344787 33.41344787 31.71922192 31.71922192
31.71922192 31.04722687 33.41344787 36.34826188 36.34826188 36.34826188
36.254 36.34826188 37.51632329 35.52726686 36.34826188 40.37142063
40.97178762 31.04722687 37.51632329 31.71922192 31.71922192 31.71922192
31.71922192 36.34826188 36.34826188 36.34826188 35.52726686 35.52726686
36.34826188 36.34826188 35.52726686 31.71922192 31.71922192 33.41344787
40.97178762 31.04722687 33.41344787 31.71922192 36.34826188 36.34826188
35.52726686 37.51632329 33.41344787 35.52726686 36.34826188 31.04722687
31.04722687 40.37142063 36.34826188 36.34826188 35.52726686 33.41344787
33.41344787 36.34826188 36.34826188 36.34826188 31.71922192 35.52726686
30.178 29.5048 27.7882 30.665 35.91111047 35.8868
34.16676364 32.53359389 30.85347634 37.25773914 37.685895 37.685895
36.22618 34.51963385 43.94671429 40.94418452 40.94418452 44.23964524
40.94418452 43.94671429 49.78195167 49.78195167 49.050525 44.23964524
43.95700001]

In [ ]: # @title Coorelation Coefficient

import pandas as pd
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import numpy as np

file:///C:/Users/Dell/Downloads/Untitled25 (2).html 7/8


5/2/24, 12:51 AM Untitled25 (2)

# Load the Slump Test dataset


data = pd.read_csv("slump_test.data")

# Separate features (X) and target variable (y)


x = data.drop(columns=['Compressive Strength (28-day)(Mpa)'])
y = data['Compressive Strength (28-day)(Mpa)']

# Split the data into training and testing sets


x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_

# Train the Random Forest Regression model


model = RandomForestRegressor(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

# Make predictions on the test set


y_pred = model.predict(x_test)

# Calculate the correlation coefficient


correlation_coefficient = np.corrcoef(y_test, y_pred)[0, 1]
print()
print("Correlation Coefficient:", correlation_coefficient)

Correlation Coefficient: 0.8907151502721642

file:///C:/Users/Dell/Downloads/Untitled25 (2).html 8/8

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy