fuzzy sql atsez eawaz fuzzy systems course june, 2005

38
Fuzzy SQL Fuzzy SQL Atsez Eawaz Atsez Eawaz Fuzzy Systems Course Fuzzy Systems Course June, 2005 June, 2005

Upload: imogene-hicks

Post on 02-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Fuzzy SQLFuzzy SQL

Atsez EawazAtsez Eawaz

Fuzzy Systems CourseFuzzy Systems Course

June, 2005June, 2005

22

SQL – Structured Query SQL – Structured Query LanguageLanguage

Presented in 1974Presented in 1974 Standardized in 1986 by ANSI and ISOStandardized in 1986 by ANSI and ISO

DML – Data Manipulation LanguageDML – Data Manipulation Language SELECT, INSERT, DELETE …SELECT, INSERT, DELETE …

DDL – Data Definition LanguageDDL – Data Definition Language CREATE, DROP, ALTERCREATE, DROP, ALTER

33

SELECT * FROM STUDENTSWHERE (GPA >= 3.5) AND (ABSENCES < 10)

NameGPAAbsences

Becky Springston4.03.0

Jeff Williams3.59.75

Leroy Jefferson3.754.5

Mike Salisbury4.01.0

Kevin Costner3.751.0

Shelly Whitman3.754.0

Barry Allen3.92.0

Billy Kidd4.09.75

John Conner4.07.0

44

SELECT * FROM STUDENTSWHERE (GPA >= 3.5) AND (ABSENCES < 10) ORDER BY GPA DESC, ABSENCES ASC;

NameGPAAbsences

Mike Salisbury4.01.0

Becky Springston4.03.0

John Conner4.07.0

Billy Kidd4.09.75

Barry Allen3.92.0

Kevin Costner3.751.0

Shelly Whitman3.754.0

Leroy Jefferson3.754.5

Jeff Williams3.59.75

55

66

77

(GPA is GOOD) AND (ABSENCES is GOOD)

Reviewing 2 SystemReviewing 2 System

1. Linux operating systemtarget DBMS Postgress

2. Written by Con OMRON LUNA88K workstation

99

Fuzzy Comparators :

Possibility ComparatorsPossibility Comparators F=, F!=, F>, F>=, F<, F<=, F>>, F<<F=, F!=, F>, F>=, F<, F<=, F>>, F<<

Necessity ComparatorsNecessity Comparators NF=, NF!=, NF>, NF>=, NF<, NF<=, NF>>, NF=, NF!=, NF>, NF>=, NF<, NF<=, NF>>,

NF<<NF<<

Inclusion Inclusion FINCL, INCLFINCL, INCL

1010

Fuzzy ConstantsFuzzy Constants

1111

Fulfillment thresholdFulfillment threshold

<condition> THOLD <condition> THOLD ττCondition must be satisfied with minimum Condition must be satisfied with minimum

degree degree ττ to be considered. to be considered.

1,0

1212

Function CDEG()Function CDEG()

CDEG (attribute)CDEG (attribute) If attribute is in condition If attribute is in condition fulfillment fulfillment

of attribute in conditionof attribute in condition Otherwise Otherwise 1 1

CDEG (*)CDEG (*) Fulfillment degree of each tuple (with all Fulfillment degree of each tuple (with all

of its attributes)of its attributes)

1313

SELECT statementSELECT statement

SELECT SELECT AA [,CDEG(*)] [,CDEG(*)]

FROM FROM RR [, <table-clause>] [, <table-clause>]

WHERE [ONCEPERGROUP]WHERE [ONCEPERGROUP]

&FQuantifier THOLD &FQuantifier THOLD ττ

(<sub query>)(<sub query>)

1414

Fuzzy Set OperatorsFuzzy Set Operators

FUNION FUNION (s-norm)(s-norm) All rows selected by either query.All rows selected by either query. If duplicated, use max CDEGIf duplicated, use max CDEG

FINTERSECT FINTERSECT (t-norm)(t-norm) All rows selected by both queries.All rows selected by both queries. If duplicated, use min CDEGIf duplicated, use min CDEG

FMINUS FMINUS (s-norm)(s-norm) All distinct rows selected by first but not All distinct rows selected by first but not

secondsecond If duplicated, use max CDEGIf duplicated, use max CDEG

1515

FuzzificationFuzzification

1616

Some ExamplesSome Examples

SELECT * FROM PlayersSELECT * FROM Players

WHERE Quality F= $Good AND WHERE Quality F= $Good AND FDEGREE(Quality) > 0.5;FDEGREE(Quality) > 0.5;

SELECT Owner.Name, Pet.FDEGROWSELECT Owner.Name, Pet.FDEGROW

FROM Pet, OwnerFROM Pet, Owner

WHERE Pet.Owner_ID = Owner.Owner_IDWHERE Pet.Owner_ID = Owner.Owner_ID

AND Pet.FDEGROW > $ AND Pet.FDEGROW > $ Very_HighVery_High

1717

1818

FDL2 – Fuzzy Database FDL2 – Fuzzy Database LibraryLibrary

Relational database consist of one or Relational database consist of one or more relationmore relation

Each relation consist of one or more Each relation consist of one or more attributesattributes

Relation Relation RR characterized by : characterized by :μμRR : D : D11 X D X D22 X … X D X … X Dnn [0,1] [0,1]

GRADE: membership value, added to GRADE: membership value, added to a relation.a relation.

1919

Example of Relation Example of Relation young young peoplepeople

2020

Fuzzy Data - 1Fuzzy Data - 1

Reliability Degree ValueReliability Degree Value Reliability degree of each stored data for Reliability degree of each stored data for

each attribute in a relationeach attribute in a relation This has [0,1] continuous values.This has [0,1] continuous values.

2121

Fuzzy Data - 2Fuzzy Data - 2

Fuzzy NumberFuzzy Number Represents fuzziness of numerical data Represents fuzziness of numerical data

like like “about 20”“about 20” Membership functionMembership function

)(0

)()/()(

)()/()(

)(0

)(

3

32233

21121

1

xx

xxxxxxx

xxxxxxx

xx

x

N

NNNNN

NNNNN

N

FN

2222

Fuzzy Data - 3Fuzzy Data - 3

wpxxx

wpxxx

NNN

NNN

223

221

FIXED methodFIXED method

RATED methodRATED method

wxx

wxx

NN

NN

23

21

2323

Fuzzy Data - 4Fuzzy Data - 4

Fuzzy LabelFuzzy Label Represents fuzziness of numerical data Represents fuzziness of numerical data

like like “young”“young” Membership functionMembership function

)(0

)()/()(

)(1

)()/()(

)(0

)(

4

43344

32

21121

1

xx

xxxxxxx

xxx

xxxxxxx

xx

x

L

LLLLL

LL

LLLLL

L

FL

2424

Fuzzy Data - 5Fuzzy Data - 5

String Fuzzy SetString Fuzzy Set Represents fuzziness of string data like Represents fuzziness of string data like

“like-red”“like-red” Fuzzy set definitionFuzzy set definition

n

iiiAxxA

1

~ /)(~

2525

Column DefinitionColumn Definition

Column that store fuzzy data should Column that store fuzzy data should be explicitly specified.be explicitly specified.

Can use column constraintCan use column constraint FUZZYFUZZY CHECKCHECK WITHWITH

2626

ExampleExample

CREATE TABLE PeopleCREATE TABLE People

( Name( Name CHAR(8)CHAR(8) NOT NULL,NOT NULL,

AgeAge DEC(3)DEC(3) FUZZY RELDEGFUZZY RELDEG

CHECK Age >= CHECK Age >= youngyoung

WITH GRADE > 0,WITH GRADE > 0,

Hair_ColorHair_Color CHAR(12)CHAR(12) FUZZY,FUZZY,

HobbyHobby CHAR(12),CHAR(12),

HeightHeight DEC(3)DEC(3) FUZZY,FUZZY,

WeightWeight Dec(3)Dec(3) FUZZY)FUZZY)

2727

Fuzzy Data Definition - 1Fuzzy Data Definition - 1

Fuzzy NumberFuzzy Number Defined by: CREATE FUZNUMDefined by: CREATE FUZNUM 3 parameters3 parameters

RATED – FIXEDRATED – FIXED Width specification valueWidth specification value Width constant valueWidth constant value

e.g. CREATE FUZNUM (RATED, 10, 2.0)e.g. CREATE FUZNUM (RATED, 10, 2.0)

2828

Fuzzy Data Definition - 2Fuzzy Data Definition - 2

Fuzzy LabelsFuzzy Labels Defined by: CREATE FUZLABDefined by: CREATE FUZLAB 4 parameters: trapezoidal coordinates4 parameters: trapezoidal coordinates

e.g. CREATE FUZLAB (young (0, 0, 20, e.g. CREATE FUZLAB (young (0, 0, 20, 30)30)

2929

Fuzzy Data Definition - 3Fuzzy Data Definition - 3

String Fuzzy SetsString Fuzzy Sets Defined by: CREATE STRFSETDefined by: CREATE STRFSET parametersparameters

names of string fuzzy setsnames of string fuzzy sets pair of elements and corresponding pair of elements and corresponding

membership valuemembership value e.g. CREATE STRFSET e.g. CREATE STRFSET

(like-red (‘red’ 1.0, ‘pink’ 0.7))(like-red (‘red’ 1.0, ‘pink’ 0.7))

3030

Fuzzy Data Definition - 4Fuzzy Data Definition - 4

Linguistic modifierLinguistic modifier Defined by: CREATE HEDGEDefined by: CREATE HEDGE ParametersParameters

modifier namemodifier name shifting method typeshifting method type shifting volumeshifting volume

e.g. CREATE HEDGEe.g. CREATE HEDGE

(very TIGHT 1, more_or_less (very TIGHT 1, more_or_less WIDE 1)WIDE 1)

3131

Fuzzy Data Definition - 5Fuzzy Data Definition - 5

Fuzzy RelationFuzzy Relation Defined by: CREATE FUZRELDefined by: CREATE FUZREL e.g. CREATE FUZRELe.g. CREATE FUZREL

(hobby_similarity(hobby_similarity

(‘Dancing’ ‘Sports’ 0.8))(‘Dancing’ ‘Sports’ 0.8))

3232

CREATE FDD young_people.ageCREATE FDD young_people.age

CREATE FUZNUM (RATED, 10, 2.0)CREATE FUZNUM (RATED, 10, 2.0)

CREATE FUZLAB (CREATE FUZLAB (

(young NMF (0, 0, 20, 30),(young NMF (0, 0, 20, 30),

old NMF (40, 50, 150, 150))old NMF (40, 50, 150, 150))

CREATE HEDGECREATE HEDGE (very TIGHT 1, more_or_less WIDE 1)(very TIGHT 1, more_or_less WIDE 1)

CREATE FDD young_people.hair_colorCREATE FDD young_people.hair_color

CREATE STRFSET (CREATE STRFSET (

like_red (‘red’ 1.0, ‘pink’ 0.7, ‘orange’ 0.3))like_red (‘red’ 1.0, ‘pink’ 0.7, ‘orange’ 0.3))

CREATE FDD young_people.hobbyCREATE FDD young_people.hobbyCREATE FUZREL (hobby_similarity (‘Dancing’ ‘Sport’ 0.8)CREATE FUZREL (hobby_similarity (‘Dancing’ ‘Sport’ 0.8)

(‘Dancing’ ‘Singing’ (‘Dancing’ ‘Singing’ 0.7))0.7))

3333

Data Manipulation - 1Data Manipulation - 1

Predicate Predicate result in grade [0,1]result in grade [0,1] =,<>,<,>,<=,>=,=,<>,<,>,<=,>=,~=,<<,>>,BETWEEN,IN,LIK~=,<<,>>,BETWEEN,IN,LIK

E, ANY,SOME,ALL,EXISTSE, ANY,SOME,ALL,EXISTS

Linguistic ModifiersLinguistic Modifiers Change the shape of membership functionChange the shape of membership function

Arithmetic OperatorArithmetic Operator

3434

Data Manipulation - 2Data Manipulation - 2

Aggregate FunctionsAggregate Functions COUNT, AVG, SUM, MIN, MAXCOUNT, AVG, SUM, MIN, MAX

Relational OperatorsRelational Operators Calculate GRADE column valueCalculate GRADE column value in UNION, max value is calculatedin UNION, max value is calculated

Limitation ConditionsLimitation Conditions Using WITH keywordUsing WITH keyword Quantity limitationQuantity limitation Quality limitationQuality limitation

3535

‘Find young people and the GRADE is greater than 0.5SELECT Name, Age, Hair_color, hobby

FROM PeopleWHERE age = youngWITH GRADE > 0.5

‘Find 20 people who are much taller than 170cm and have like red hair colorSELECT name, height, weight

FROM PeopleWHERE (height >> 170) AND (Hair_color = like_red)WITH LINES = 20

‘Find the people who are age is young (0.6) and income is high (1.0)‘REL : Reliability degree value‘0.6 and 1.0 : Importance degree value of each argument of mean operatorSELECT name, age, income

FROM PeopleWHERE MEAN ( (age = young, REL(age) * 0.6) ,

(income >= high, REL(income) * 1.0)

3636

Architecture of Fuzzy Database using FDL2

3737

ReferencesReferences

1. A.Urrutia, L.Pavesi, “1. A.Urrutia, L.Pavesi, “Extending the capabilities of Extending the capabilities of database queries using fuzzy logicdatabase queries using fuzzy logic”, University of ”, University of Maule, 2004.Maule, 2004.

2. H.Nakajima, 2. H.Nakajima, et alet al, “, “Fuzzy database language and Fuzzy database language and librarylibrary”, FUZZ-IEEE’93, pp. 477-482.”, FUZZ-IEEE’93, pp. 477-482.

3. P.Bosc, 3. P.Bosc, et alet al, “, “SQLf: A relational database language SQLf: A relational database language for fuzzy queryingfor fuzzy querying”, 1995, IEEE Trans on Fuzzy ”, 1995, IEEE Trans on Fuzzy Systems, 3, pp. 1-17.Systems, 3, pp. 1-17.

4. P.Bosc, 4. P.Bosc, et alet al, “, “Fuzzy querying with SQL: extension Fuzzy querying with SQL: extension and implementation aspectsand implementation aspects”, 1998, Fuzzy Set and ”, 1998, Fuzzy Set and Systems, 28, pp. 333-349.Systems, 28, pp. 333-349.

5. http://fuzzy5. http://fuzzy..sonalystssonalysts..comcom

3838

Thanks for your patientThanks for your patient

Any question ?Any question ?