SISTEMAS PERICIAIS Métodos de inferência: Forward

Transcrição

SISTEMAS PERICIAIS Métodos de inferência: Forward
SISTEMAS PERICIAIS
Fase de construção
Módulo de
Aquisição de
Conhecimento
Base de
Conhecimento
Engenheiro de
conhecimento
Motor de Inferência
(Sistema de Gestão de
Bases de Conhecimento)
Módulo
de
Explicações
Interface com Utilizador
Fase de utilização
Peritos /
especialistas
Utilizador
Métodos de inferência:
Forward Chaining
•
•
•
Given some facts, work forward through inference net.
Discovers what conclusions can be derived from data.
If more than one rule matches
o may fire all rules and simulate parallel machine
o may select only one rule
Supervisão Inteligente
Exemplo em Robótica:
Sensor de força
Fx, Fy, Fz
Sensor de força do dedo
Detector de objecto
Factos:
Detector_objecto inactivo
Fz = 10.25
Fx = 0.02
Fy = 0.015
Garra aberta
Força_dedo = 1.2
...
Regras:
R1: if pesado and objeto detectado na garra then preensão bem sucedida
R2: if Fz >= 1.5 then pesado
R3: if detector_objecto activo then objecto detectado na garra
R4: if detector_objecto inactivo and not pesado then garra vazia
R5: if garra aberta and força_dedo > 0.5 then objecto detectado na garra
R6: if Fx-Fy <= 0.05 then peça centrada na garra
...
Inferência "forward":
Foi a preensão bem sucedida ?
Regras satisfeitas com
factos correntes:
R2
R5
R6
Novos factos inferidos pela aplicação
destas regras e adicionados à base:
pesado
objecto detectado na garra
peça centrada na garra
Regras satisfeitas pela base de factos actualizada:
R1
...
Supervisão Inteligente
após aplicação --> novo facto: preensão bem sucedida
Backward Chaining
•
•
To determine if a decision should be made, work backwards looking for
justifications for the decision.
Eventually, a decision must be justified by facts.
Exemplo em robótica:
Sensor de força
Fx, Fy, Fz
Sensor de força do dedo
Detector de objecto
Factos:
Detector_objecto inactivo
Fz = 10.25
Fx = 0.02
Fy = 0.015
Garra aberta
Força_dedo = 1.2
...
Regras:
R1: if pesado and objeto detectado na garra then preensão bem sucedida
R2: if Fz >= 1.5 then pesado
R3: if detector_objecto activo then objecto detectado na garra
R4: if detector_objecto inactivo and not pesado then garra vazia
Supervisão Inteligente
R5: if garra aberta and força_dedo > 0.5 then objecto detectado na garra
R6: if Fx-Fy <= 0.05 then peça centrada na garra
...
Inferência "backward":
Foi a preensão bem sucedida ?
sim
R1: pesado and objecto detectado na garra ?
sim
R2: Fz >= 1.5 ?
não
R3: detector de objecto activado ?
sim
sim
Facto: Fz = 10.25
facto: não
R5: garra aberta and força_dedo > 0.5 ?
sim
Facto: garra aberta
sim
Facto: força_dedo = 1.2
Exercício:
Qual o melhor método de inferência nos seguintes casos:
•Visão artificial:
-Que objecto estou vendo?
-Será que este objecto é um parafuso?
•Planeamento ?
•Diagnóstico ?
EXPLANATIONS
•
•
The system must be able to explain how it arrived to a conclusion and why
it is performing some computation.
It may also be required answer what if questions
Supervisão Inteligente
Answering HOW?
•
•
•
To answer how a conclusion was reached, work back through the
inference chain.
Decision 4 was made as a result of making decision 1 and decision 2.
Decision 1 was made because Facts 1, 2 & 3 are true, etc.
Example WILLARD:
- Since upper level cold air advection causing increased upwards vertical
velocities is present it follows that the upper-level destabilization potential
is sufficient
- Since the K index is strong when the lifted index is strong it follows that
the stability indices condition is favorable
- Since …
It was necessary to advice:
“There is a SLIGHT CHANCE thunderstorms occurring 12 hours from now
will be severe at this location”
Answering WHY?
•
•
To answer why a computation is being performed, the system must state
its current goal.
The system may ask the user if fact 3 is true because it is trying to
determine if decision 1 should be made.
Supervisão Inteligente
Example MYCIN:
- Is the patient’s illness with ORGANISM-1 a hospital acquired infection?
** WHY?
[i.e. Why is it important to determine whether or not the infection with
ORGANISM-1 was acquired while the patient was hospitalized?]
[1.0] This will add in determining the category of ORGANISM-1.
It was already established that
[1.1] the gram stain of ORGANISM-1 is gramneg and
[1.2] the morphology of ORGANISM-1 is rod, and
[1.3] the aerobicity of ORGANISM-1 is facultative
Therefore, if
[1.4] the infection with ORGANISM-1 was not acquired while the patient
was hospitalized
then
There is strongly suggestive evidence (0.8) that the category of
ORGANISM-1 is enterobacteriaceae
Also:
There is weakly suggestive evidence (-1) that the identity of
ORGANISM-1 is pseudomonas-aeruginosa
Sistemas baseados em Conhecimento
Software de
Aplicação
Base de
Conhecimento
KB
•Factos, conceitos
•Regras
Motor de
Inferência
KBMS
Núcleo dum Sistema Baseado em Conhecimento
Supervisão Inteligente
Pode extrair informação que
está explicitamente armazenada
na KB (factos, conceitos)
Pode inferir novos factos
pela aplicação de regras,
mecanismos de herança, etc.
EXEMPLOS DE “SHELLS”
CLIPS
C Language Integrated Production System
NASA > 1985
Open source
Forward
OOP
www.ghg.net/clips/CLIPS.html
JESS
Java Expert System Shell
Inspirado no CLIPS
Gratuito para uso académico
Forward + Backward
http://herzberg.ca.sandia.gov/jess/
EXSYS CORVID
Comercial
Regras, objectos
Backward, Forward
Raciocínio fuzzy e probabilístico
Interface web, suporta múltiplas linguagens
www.exsys.com
Mais exemplos:
www.kbsc.com/rulebase.html
www.cs.utexas.edu/users/mfkb/related.html
Tutorial:
http://en.wikipedia.org/wiki/Expert_system
Supervisão Inteligente
SISTEMAS PERICIAIS PARA TEMPO REAL
Algumas características:
Não monoticidade
o Os dados não se mantêm ao longo do tempo
o Os dados perdem validade
Raciocínio temporal
o Sobre eventos passados, presentes e futuros
Ligação com sistemas externos
o Dispositivos físicos
o Software externo
o Fontes de dados externas
Eventos assíncronos
Focalização
o Alteração rápida do foco de atenção
EXEMPLO: RT-EXPERT
Artis Corp.
C calling
program
RTSUB
[rule set subroutine]
RTSUB
[rule set subroutine]
RTSUB
[rule set subroutine]
Módulos de raciocínio / tomada de decisão
embebidos num programa tradicional
if ... then ... else ... ;
DSL
Decision Support Language
[Ada like syntax]
Cada RTSUB num
ficheiro separado
Cada conjunto de regras (ex. 10 a 30 regras)
pode ser visto como um domínio de decisão
– ex. Supervisão dum dispositivo
Chamados repetidamente !!!
if ... then ... ;
if temperatura > 70 then aquecedor := ON else aquecedor := OFF ;
Supervisão Inteligente
Variáveis DSL
value
-> pode ser undefined
time
-> tempo da última alteração
Importance -> importância da informação contida na variável
A parte <condição> das regras é re-avaliada se e só se as variáveis que
aí aparecem tiverem sido alteradas desde o último disparo das regras.
Para determinar qual a regra a disparar primeiro quando várias regras
podem ser disparadas.
variavel’time
variavel’importance
Apontador para um record
(variável DSL)
As únicas que podem levar ao
disparo de regras
Regras
Inicialização
RTSUB temp_ctl (temperature: ATTRIB FLOAT;
contrl: ATTRIB SYMBOLIC;
heater: ATTRIB SYMBOLIC;
lo_limit, hi_limit: IN FLOAT) IS
O atributo
DECLARE
“time” será
usado para
RUN, STOP, ON, OFF ARE SYMBOLIC CONSTANT;
determinar se as
INIT
regars devem
PRAGMA RULE_TRIGGER IS NEW_DATA;
ser (re-)
avaliadas
BEGIN – Start of RTSUB rules
IF control =RUN AND heater =undefined THEN heater := ON;
IF control = undefined OR control =STOP THEN heater := OFF;
IF temperature > hi_limit AND heater =ON AND
time_now – heater’time > 3 seconds AND
Se isto não
fosse indicado
control = RUN THEN heater := OFF;
era assumido que todos
os parâmetros tinham
IF temperature < lo_limit AND heater = OFF AND
mudado desde a
time_now – heater’time > 3 seconds AND
última chamada a
temp_ctl
control = RUN THEN heater := ON;
END;
Comentário
Afecta não só o valor do
atributo, mas também o “time”
Supervisão Inteligente
Chamada a partir dum
programa C
...
#include “temp_ctl.h”
...
main ()
{
static dsl_FLOAT temperature:
static dsl_SYMBOL control;
static dsl_SYMBOL heater;
float lo_limit, hi_limit;
lo_limit = 90.0; hi_limit = 110.0;
...
init_temp_ctl(&temperature, &control, &heater, lo_limit, hi_limit);
...
while (1)
{
...
temp_ctl(&temperature, &control, &heater, lo_limit, hi_limit);
...
}
}
Procedimentos C gerados
pelo compilador RTX
-Determina um equivalente numérico
para as constantes simbólicas
-Inicializa o campo “value” das variáveis
DSL
-Inicializa o “time” com o valor do tempo
actual
-Executa a parte INIT do módulo RTSUB
-...
RTSUB temp_ctl (temperature: ATTRIB FLOAT;
contrl: ATTRIB SYMBOLIC;
heater: ATTRIB SYMBOLIC;
lo_limit, hi_limit: IN FLOAT) IS
...
INIT
...
...
BEGIN
...
...
END;
Data-driven vs. procedimental
Data
driven
Procedimental
(sequencial)
IF time_now – temperature’time > 1 THEN
BEGIN
temperature := get_input;
PRINC “temperature is “, temperature, “ at “, time_now;
END;
Ordem de execução das regras
LEXICAL – a importância é dada pela sequência da declaração
(assumido em caso de omissão)
DATA – a importância da regra é herdada da importância do seu mais
recente item de dados
RECENCY – Precedência dada à regras cujas variáveis (da parte condição)
foram modificadas mais recentemente
=> PRAGMA ORDER
Supervisão Inteligente
#include <rtx.h>
#include “temp_ctl.h”
#include “set_heat.h”
#include “get_temp.h”
#include “get_ctl.h”
main ()
{
static dsl_FLOAT temperature:
static dsl_SYMBOL control;
static dsl_SYMBOL heater;
float lo_limit, hi_limit;
lo_limit = 90.0; hi_limit = 110.0;
init_temp_ctl(&temperature, &control, &heater, lo_limit, hi_limit);
Init_set_heater(&heater);
Init_get_temperature(&temperature);
Init_get_ctl(&control);
while (1)
{
get_ctl(&control);
get_temperature(&temperature);
temp_ctl(&temperature, &control, &heater, lo_limit, hi_limit);
set_heater(&heater);
}
}
RTSUB temp_ctl (temperature: ATTRIB FLOAT;
contrl: ATTRIB SYMBOLIC;
heater: ATTRIB SYMBOLIC;
lo_limit, hi_limit: IN FLOAT) IS
DECLARE
RUN, STOP, ON, OFF ARE SYMBOLIC CONSTANT;
INIT
PRAGMA RULE_TRIGGER IS NEW_DATA;
BEGIN – Start of RTSUB rules
IF control =RUN AND heater =undefined THEN heater := ON;
IF control = undefined OR control =STOP THEN heater := OFF;
IF temperature > hi_limit AND heater =ON AND
time_now – heater’time > 3 seconds AND
control = RUN THEN heater := OFF;
IF temperature < lo_limit AND heater = OFF AND
time_now – heater’time > 3 seconds AND
control = RUN THEN heater := ON;
END;
RTSUB get_temperature( temperature: ATTRIB FLOAT) IS
DECLARE
DYNAMIC FUNCTION get_input RETURN FLOAT;
INIT
temperature := get_input;
BEGIN
IF time_now – temperature’time > 1 second THEN
BEGIN
temperature := get_input;
PRINC “temperatur is “, temperature, “ at “, time_now;
END;
END;
RTSUB set_heater(heater: ATTRIB SYMBOL) IS
DECLARE
PROCEDURE set_output(val: SHORT);
ON, OFF ARE SYMBOLIC CONSTANT;
INIT
PRAGMA RULE_TRIGGER IS NEW_DATA;
BEGIN
IF heater HAS CHANGED THEN PRINC “heater “, heater;
IF heater = ON THEN set_output(1);
IF heater = OFF THEN set_output(0);
END;
RTSUB get_ctl(control: ATTRIB SYMBOL) IS
DECLARE
RUN, STOP ARE SYMBOLIC CONSTANT;
c IS CHAR;
DYNAMIC TIME FUNCTION kbhit RETURN INT;
DYNAMIC FUNCTION getch RETURN CHAR;
PROCEDURE exit(errcode: IN INT);
BEGIN
IF kbhit /= 0 THEN c := getch;
IF c = ESC THEN exit(0);
IF c = ‘r’ OR c = ‘R’ THEN control := RUN;
IF c = ‘s’ OR c = ‘S’ THEN control := STOP;
IF c HAS CHANGED THEN PRINC “Control is “, control;
END;
Diferenças em relação aos sistemas periciais tradicionais:
-Orientado para a construção de sistemas de tempo-real
-Regras são compiladas, não interpretadas
-As regras são disparadas num modelo “data-flow”
-As variáveis têm tipos, para permitir verificação pelo compilador
-Orientadas para raciocinar sobre o tempo em que eventos ocorrem
-Podem efectuar cálculos sobre variáveis que estão definidas apenas em
períodos limitados de tempo
-As regras podem ser automaticamente re-disparadas pela passagem do
tempo
-As regras podem incluir uma parte “else”
A base de regras não é “monolítica”.
A modularização é incentivada
– cada RTSUB contém um pequeno número de regras
Supervisão Inteligente
EXEMPLO:
CORVID
[EXSYS Corp.]
Inference
- Forward
- Backward
- Confidence factors
Interface Java / Web
Access to external DB (SQL)
Variables with prompts
Variables with properties
[Desired_features.COUNT] would return the number of selected items
[Desired_features.HOW] would return a detailed text explanation of how the
value for the variable was set that could be used in the results or a report.
IF
It is raining
THEN
You should wear a raincoat
IF
The customer has high-risk tolerance
AND
Meeting objectives requires rapid growth
THEN
Mutual Fund X is a good choice
IF
The customer has high-risk tolerance
AND
Meeting objectives requires rapid growth
THEN
Mutual Fund X is a good choice
IF
The customer has high-risk tolerance
AND
Meeting objectives requires only medium or slow growth
THEN
Mutual Fund Z is a good choice
IF
The customer has medium risk tolerance
THEN
Mutual Fund Y is a good choice
AND
Mutual Fund X is a poor choice
IF
The customer has low risk tolerance
THEN
Mutual Fund X is a poor choice
Supervisão Inteligente

Documentos relacionados