Dodanie reguł fuzzy logic
This commit is contained in:
parent
8e29a715a5
commit
9679aaf720
@ -0,0 +1,84 @@
|
||||
import numpy as np
|
||||
import skfuzzy as fuzz
|
||||
from skfuzzy import control as ctrl
|
||||
|
||||
|
||||
def get_fuzzy_response(request_params):
|
||||
|
||||
# Stworzenie uniwersum
|
||||
production_year = ctrl.Antecedent(np.arange(1960, 2022, 1), 'production_year')
|
||||
mileage = ctrl.Antecedent(np.arange(0, 500000, 1), 'mileage')
|
||||
engine_capacity = ctrl.Antecedent(np.arange(0.7, 8.2, 0.1), 'engine_capacity')
|
||||
combustion = ctrl.Consequent(np.arange(4.0, 15.0, 0.1), 'combustion')
|
||||
|
||||
# Generowanie przykładowych danych dla uniwersum
|
||||
production_year.automf(3)
|
||||
mileage.automf(3)
|
||||
engine_capacity.automf(3)
|
||||
combustion.automf(3)
|
||||
|
||||
|
||||
# Tworzenie funkcji rozmytych
|
||||
production_year['low'] = fuzz.trimf(production_year.universe, [1960, 1960, 2001])
|
||||
production_year['mid'] = fuzz.trimf(production_year.universe, [1960, 2001, 2022])
|
||||
production_year['high'] = fuzz.trimf(production_year.universe, [2017, 2022, 2022])
|
||||
|
||||
mileage['low'] = fuzz.trimf(mileage.universe, [0, 0, 50000])
|
||||
mileage['mid'] = fuzz.trimf(mileage.universe, [0, 300000, 500000])
|
||||
mileage['high'] = fuzz.trimf(mileage.universe, [300000, 500000, 500000])
|
||||
|
||||
engine_capacity['low'] = fuzz.trimf(engine_capacity.universe, [0.7, 0.7, 1.2])
|
||||
engine_capacity['mid'] = fuzz.trimf(engine_capacity.universe, [1.2, 2.0, 8.2])
|
||||
engine_capacity['high'] = fuzz.trimf(engine_capacity.universe, [5.0, 8.2, 8.2])
|
||||
|
||||
combustion['low'] = fuzz.trimf(combustion.universe, [4.0, 4.0, 6.0])
|
||||
combustion['mid'] = fuzz.trimf(combustion.universe, [4.0, 8.0, 15.0])
|
||||
combustion['high'] = fuzz.trimf(combustion.universe, [8.5, 15.0, 15.0])
|
||||
|
||||
|
||||
rules = []
|
||||
if 'production_year' in request_params:
|
||||
rules.append(('production_year', request_params['production_year']))
|
||||
if 'mileage' in request_params:
|
||||
rules.append(('mileage', request_params['mileage']))
|
||||
if 'engine_capacity' in request_params:
|
||||
rules.append(('engine_capacity', request_params['engine_capacity']))
|
||||
if 'combustion' in request_params:
|
||||
rules.append(('combustion', request_params['combustion']))
|
||||
|
||||
|
||||
combustion_rule = ctrl.Rule(production_year[request_params['production_year']] & mileage[request_params['mileage']] & engine_capacity[request_params['engine_capacity']], combustion[request_params['combustion']])
|
||||
# engine_capacity_rule = ctrl.Rule(production_year[request_params['production_year']] & mileage[request_params['mileage']] & combustion[request_params['combustion']], engine_capacity[request_params['engine_capacity']])
|
||||
# production_year_rule = ctrl.Rule(engine_capacity[request_params['engine_capacity']] & mileage[request_params['mileage']] & combustion[request_params['combustion']], production_year[request_params['production_year']])
|
||||
# mileage_rule = ctrl.Rule(engine_capacity[request_params['engine_capacity']] & production_year[request_params['production_year']] & combustion[request_params['combustion']], mileage[request_params['mileage']])
|
||||
|
||||
|
||||
combustion_ctrl = ctrl.ControlSystemSimulation(ctrl.ControlSystem([combustion_rule]))
|
||||
# engine_ctrl = ctrl.ControlSystemSimulation(ctrl.ControlSystem([engine_capacity_rule]))
|
||||
# production_year_ctrl = ctrl.ControlSystemSimulation(ctrl.ControlSystem([production_year_rule]))
|
||||
# mileage_ctrl = ctrl.ControlSystemSimulation(ctrl.ControlSystem([mileage_rule]))
|
||||
|
||||
combustion_ctrl.input['production_year'] = 2015
|
||||
combustion_ctrl.input['mileage'] = 20000
|
||||
combustion_ctrl.input['engine_capacity'] = 1.4
|
||||
combustion_ctrl.compute()
|
||||
print(combustion_ctrl.output['combustion'])
|
||||
|
||||
# engine_ctrl.inputs['production_year'] = 2011
|
||||
# engine_ctrl.inputs['mileage'] = 66000
|
||||
# engine_ctrl.inputs['combustion'] = 7.3
|
||||
# engine_ctrl.compute()
|
||||
# print(engine_ctrl.output['engine_capacity'])
|
||||
|
||||
# production_year_ctrl.inputs['engine_capacity'] = 8.0
|
||||
# production_year_ctrl.inputs['mileage'] = 200000
|
||||
# production_year_ctrl.inputs['combustion'] = 12
|
||||
# production_year_ctrl.compute()
|
||||
# print(production_year_ctrl.output['production_year'])
|
||||
|
||||
# mileage_ctrl.inputs['engine_capacity'] = 1.4
|
||||
# mileage_ctrl.inputs['production_year'] = 2007
|
||||
# mileage_ctrl.inputs['combustion'] = 6.2
|
||||
# mileage_ctrl.compute()
|
||||
# print(mileage_ctrl.output['mileage'])
|
||||
|
@ -1,5 +1,6 @@
|
||||
from rest_framework import generics
|
||||
from rest_framework.response import Response
|
||||
from .fuzzy_logic import get_fuzzy_response
|
||||
from .models import Car
|
||||
from .serializers import CarSerializer
|
||||
from .utils import map_query_params
|
||||
@ -10,6 +11,8 @@ class CarList(generics.ListAPIView):
|
||||
|
||||
def list(self, request):
|
||||
values = map_query_params(request.query_params)
|
||||
response = get_fuzzy_response(values)
|
||||
print(response)
|
||||
queryset = self.get_queryset()
|
||||
serializer = CarSerializer(queryset, many=True)
|
||||
return Response(serializer.data)
|
59
backend/requirements.txt
Normal file
59
backend/requirements.txt
Normal file
@ -0,0 +1,59 @@
|
||||
amqp==5.0.9
|
||||
asgiref==3.4.1
|
||||
attrs==21.4.0
|
||||
billiard==3.6.4.0
|
||||
black==21.10b0
|
||||
celery==5.1.2
|
||||
cfgv==3.3.1
|
||||
click==7.1.2
|
||||
click-didyoumean==0.3.0
|
||||
click-plugins==1.1.1
|
||||
click-repl==0.2.0
|
||||
cycler==0.11.0
|
||||
distlib==0.3.4
|
||||
Django==3.2.9
|
||||
django-cors-headers==3.10.0
|
||||
django-environ==0.4.5
|
||||
django-filter==21.1
|
||||
djangorestframework==3.12.4
|
||||
filelock==3.4.2
|
||||
fonttools==4.28.5
|
||||
identify==2.4.4
|
||||
iniconfig==1.1.1
|
||||
isort==5.9.3
|
||||
kiwisolver==1.3.2
|
||||
kombu==5.2.3
|
||||
matplotlib==3.5.1
|
||||
mypy-extensions==0.4.3
|
||||
networkx==2.6.3
|
||||
nodeenv==1.6.0
|
||||
numpy==1.22.1
|
||||
packaging==21.3
|
||||
pathspec==0.9.0
|
||||
pep517==0.12.0
|
||||
Pillow==9.0.0
|
||||
pip-tools==6.4.0
|
||||
pkg_resources==0.0.0
|
||||
platformdirs==2.4.1
|
||||
pluggy==1.0.0
|
||||
pre-commit==2.15.0
|
||||
prompt-toolkit==3.0.24
|
||||
psycopg2-binary==2.9.1
|
||||
py==1.11.0
|
||||
pyparsing==3.0.6
|
||||
pytest==6.2.5
|
||||
pytest-django==4.4.0
|
||||
python-dateutil==2.8.2
|
||||
pytz==2021.3
|
||||
PyYAML==6.0
|
||||
regex==2021.11.10
|
||||
scikit-fuzzy==0.4.2
|
||||
scipy==1.7.3
|
||||
six==1.16.0
|
||||
sqlparse==0.4.2
|
||||
toml==0.10.2
|
||||
tomli==1.2.3
|
||||
typing_extensions==4.0.1
|
||||
vine==5.0.0
|
||||
virtualenv==20.13.0
|
||||
wcwidth==0.2.5
|
19380
frontend/package-lock.json
generated
19380
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user