IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SAS Base Discussion :

Fonctions linéraires par morceaux


Sujet :

SAS Base

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    35
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2014
    Messages : 35
    Points : 33
    Points
    33
    Par défaut Fonctions linéraires par morceaux
    Bonjour,
    j'aimerais construire des fonctions linéraires par morceaux qui seraient mes variables, en fonctions de certains paramètres que j'ai à ma disposition.
    Je m'explique:
    j'ai une base, sur laquelle j'ai récupéré des min et des max de variables, qu'à l'aide de call symputx j'ai mis dans les macro-variables min_1, min_2, min_3, min_4, min_5 et max_1, max_2, max_3, max_4, max_5.
    Ensuite, dans une autre base, j'ai juste une liste d'abscisses qui va de 1 à 12 avec un pas de 0.1 (donc 120 valeurs).
    Je veux construire 3 variables, var1, var2, var3, var4, var5 telles que:
    -var1 vaut 1 lorsque abscisse est plus petit que 100*(min_1+(max_2-min_1)/3), vaut 0 lorsuqe abcisse est plus grand que 100*(min_1+(max_2-min_1)/3), et décroit linérairement entre les 2.
    - var2 vaut 0 avant 100*(min_1+(max_2-min_1)/3), croit linérairement jusqu'à ce que abscisse vaut 100*(min_1+(max_2-min_1)/3), puis vaut 1 jusqu'à 100*(&max_2+(&min_3-&max_2)/3), puis décroit linéairement jusqu'à abscisse=100*(&min_3-(&min_3-&max_2)/3), puis vaut 0 jusqu'à la fin.
    -etc.

    la forme générale des variables, une fois tracée (sur ce graph, les proportions ne sont pas respectées, c'est juste la forme)Pièce jointe 154332

    J'ai donc écrit un code tout simple pour les parties qui valent 0 ou 1, mais je n'arrive pas à faire les parties non constantes.
    J'ai tenté une macro, mais elle ne fonctionne pas...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
     
    Data appartenance_txrp_sortie;
    DO numero=1 TO 10*&borne;
    OUTPUT;
    END;
    RUN;
    data appartenance_txrp_sortie;set appartenance_txrp_sortie;by numero;
    if first.numero then abscisse+0.1;run;
    data appartenance_txrp_sortie;set appartenance_txrp_sortie;
    if abscisse<=100*(&max_1+(&min_2-&max_1)/3) then txrach1=1;
    if abscisse<=100*(&max_1+(&min_2-&max_1)/3) then txrach2=0;
    if abscisse<=100*(&max_1+(&min_2-&max_1)/3) then txrach3=0;
    if abscisse<=100*(&max_1+(&min_2-&max_1)/3) then txrach4=0;
    if abscisse<=100*(&max_1+(&min_2-&max_1)/3) then txrach5=0;
     
    if (abscisse>=100*(&min_2-(&min_2-&max_1)/3) and abscisse<=100*(&max_2+(&min_3-&max_2)/3)) then txrach1=0; 
    if (abscisse>=100*(&min_2-(&min_2-&max_1)/3) and abscisse<=100*(&max_2+(&min_3-&max_2)/3)) then txrach2=1; 
    if (abscisse>=100*(&min_2-(&min_2-&max_1)/3) and abscisse<=100*(&max_2+(&min_3-&max_2)/3)) then txrach3=0; 
    if (abscisse>=100*(&min_2-(&min_2-&max_1)/3) and abscisse<=100*(&max_2+(&min_3-&max_2)/3)) then txrach4=0; 
    if (abscisse>=100*(&min_2-(&min_2-&max_1)/3) and abscisse<=100*(&max_2+(&min_3-&max_2)/3)) then txrach5=0; 
     
    if (abscisse>=100*(&min_3-(&min_3-&max_2)/3) and abscisse<=100*(&max_3+(&min_4-&max_3)/3)) then txrach1=0; 
    if (abscisse>=100*(&min_3-(&min_3-&max_2)/3) and abscisse<=100*(&max_3+(&min_4-&max_3)/3)) then txrach2=0; 
    if (abscisse>=100*(&min_3-(&min_3-&max_2)/3) and abscisse<=100*(&max_3+(&min_4-&max_3)/3)) then txrach3=1; 
    if (abscisse>=100*(&min_3-(&min_3-&max_2)/3) and abscisse<=100*(&max_3+(&min_4-&max_3)/3)) then txrach4=0; 
    if (abscisse>=100*(&min_3-(&min_3-&max_2)/3) and abscisse<=100*(&max_3+(&min_4-&max_3)/3)) then txrach5=0;
     
    if (abscisse>=100*(&min_4-(&min_4-&max_3)/3) and abscisse<=100*(&max_4+(&min_5-&max_4)/3)) then txrach1=0;  
    if (abscisse>=100*(&min_4-(&min_4-&max_3)/3) and abscisse<=100*(&max_4+(&min_5-&max_4)/3)) then txrach2=0;
    if (abscisse>=100*(&min_4-(&min_4-&max_3)/3) and abscisse<=100*(&max_4+(&min_5-&max_4)/3)) then txrach3=0;
    if (abscisse>=100*(&min_4-(&min_4-&max_3)/3) and abscisse<=100*(&max_4+(&min_5-&max_4)/3)) then txrach4=1;
    if (abscisse>=100*(&min_4-(&min_4-&max_3)/3) and abscisse<=100*(&max_4+(&min_5-&max_4)/3)) then txrach5=0;
     
    if abscisse>=100*(&min_5-(&min_5-&max_4)/3) then txrach1=0;
    if abscisse>=100*(&min_5-(&min_5-&max_4)/3) then txrach2=0;
    if abscisse>=100*(&min_5-(&min_5-&max_4)/3) then txrach3=0;
    if abscisse>=100*(&min_5-(&min_5-&max_4)/3) then txrach4=0;
    if abscisse>=100*(&min_5-(&min_5-&max_4)/3) then txrach5=1;
     
    run;
    data appartenance_txrp_sortie;set appartenance_txrp_sortie;
    if (abscisse>100*(&max_1+(&min_2-&max_1)/3) and abscisse<100*(&min_2-(&min_2-&max_1)/3)) then txrach3=0;
    if (abscisse>100*(&max_1+(&min_2-&max_1)/3) and abscisse<100*(&min_2-(&min_2-&max_1)/3)) then txrach4=0;
    if (abscisse>100*(&max_1+(&min_2-&max_1)/3) and abscisse<100*(&min_2-(&min_2-&max_1)/3)) then txrach5=0;
     
     
    if (abscisse>100*(&max_2+(&min_3-&max_2)/3) and abscisse<100*(&min_3-(&min_3-&max_2)/3)) then txrach1=0;
    if (abscisse>100*(&max_2+(&min_3-&max_2)/3) and abscisse<100*(&min_3-(&min_3-&max_2)/3)) then txrach4=0;
    if (abscisse>100*(&max_2+(&min_3-&max_2)/3) and abscisse<100*(&min_3-(&min_3-&max_2)/3)) then txrach5=0;
     
    if (abscisse>100*(&max_3+(&min_4-&max_3)/3) and abscisse<100*(&min_4-(&min_4-&max_3)/3)) then txrach5=0;
    if (abscisse>100*(&max_3+(&min_4-&max_3)/3) and abscisse<100*(&min_4-(&min_4-&max_3)/3)) then txrach1=0;
    if (abscisse>100*(&max_3+(&min_4-&max_3)/3) and abscisse<100*(&min_4-(&min_4-&max_3)/3)) then txrach2=0;
     
    if (abscisse>100*(&max_4+(&min_5-&max_4)/3) and abscisse<100*(&min_5-(&min_5-&max_4)/3)) then txrach1=0;
    if (abscisse>100*(&max_4+(&min_5-&max_4)/3) and abscisse<100*(&min_5-(&min_5-&max_4)/3)) then txrach2=0;
    if (abscisse>100*(&max_4+(&min_5-&max_4)/3) and abscisse<100*(&min_5-(&min_5-&max_4)/3)) then txrach3=0;
    run;
    %macro pente(alpha, beta,a,b); /*macro pour les parties linéaires, ne marche pas*/
    %let k=(&beta-&alpha)/0.1;
    %let i=1;
    %do %while (abscisse<&beta and abscisse>&alpha);
    txrach&a=1-&i*(&beta-&alpha)/&k;
    txrach&b=&i*(&beta-&alpha)/&k;
    %let i=&i+1;
    %end;
    %mend;
    data appartenance_txrp_sortie;set appartenance_txrp_sortie; /*ne marche pas*/
    %pente(100*(&max_1+(&min_2-&max_1)/3),(&min_2-(&min_2-&max_1)/3),1,2);
    run;

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 83
    Points : 137
    Points
    137
    Par défaut
    Bonjour,
    Tu peux construire directement le tout dans une étape data avec do et output, par exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
     
    data test;
     
    	seuil1=100*(&max_1+(&max_2-&min_1)/3);
    	seuil2=100*(&min_1+(&max_2-&min_1)/3);
    	seuil3=100*(&max_2+(&min_3-&max_2)/3);
    	do x=0 to seuil1 by 0.1;	
    		var2=0;
    		output;
    	end;
    	a=3.4;
    	b=46;
    	do x=seuil1 to seuil2 by 0.1;
    		var2=a*x+b;
    		output;
    	end;
    	do x=seuil1 to seuil2 by 0.1;
    		var2=1;
    		output;
    	end;
    	a=-4.1;
    	b=40;
    	do x=seuil2 to seuil3 by 0.1;
    		output;
    	end;
    	keep x var2;
    run;

Discussions similaires

  1. [Débutant] Transfomée de Laplace d'une fonction définie par morceaux
    Par tibmaster dans le forum MATLAB
    Réponses: 0
    Dernier message: 14/12/2014, 22h01
  2. Interpolation de fonction définie par morceaux
    Par Benmu dans le forum MATLAB
    Réponses: 2
    Dernier message: 17/07/2014, 14h32
  3. fonction affine par morceaux
    Par xavierdestev dans le forum Scilab
    Réponses: 2
    Dernier message: 05/12/2013, 11h55
  4. fonction régulière par morceaux et d'ordre exponentiel
    Par ministeur dans le forum Mathématiques
    Réponses: 3
    Dernier message: 03/04/2012, 19h28
  5. fonction constante par morceaux
    Par lamine10 dans le forum Signal
    Réponses: 1
    Dernier message: 19/08/2010, 15h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo