Problem with technical condition analyzer

6 ビュー (過去 30 日間)
Ivan Khomich
Ivan Khomich 2020 年 10 月 29 日
This program is aimed at analyzing the technical condition of an object according to the criterion of maximum buffering. To determine the technical condition of an object means to find out whether it has a set of required properties that ensure its suitability for the intended use and the correct performance of its functions directly in the process of application, and if it does not, then due to what defects. The process of determining the technical condition includes monitoring the technical condition and technical diagnostics. Diagnostics is the process of examining an object in order to determine (recognize) its condition.
In diagnostics, the average conditional probability of correctly determining the technical condition of an object is used as a confidence indicator.
Let's describe in simple words the essence of the actions required for diagnosis. The source data is a table consisting of Si - condition of the object (subsystems of a system can act as Si); pj-signs that are used for checking conditions; numbers in the table – operating modes of the system (for example: 1-fully functional condition, 2 – partially functional, 3-completely inoperable); a – error of the first kind; b – error of the second kind; P(Si) – condition probabilities.
This table presented in the code by the Matrix A, wherein Si - is rows, and pj - columns.
The system as a whole is analyzed by analyzing its subsystems, that is, s1s2s3s4s5s6 is analyzed due to the functioning of all possible combinations of subsystems, from pairs to conditions of 5 elements (from SiSj to SiSjSkSlSm). SiSjSkSlSmSn – initial state, SiSj to SiSjSkSlSm-non-finite States, Si-final state.
The goal of creating the program is to find the reliability and optimal feature at each step.
There is a problem of dividing the initial state due to the optimal reliability of features to the final states. This problem will be solved using an algorithm directed in the opposite direction, that is, the analysis will be performed from the final state to the initial one. The problem of my code is the need to automatically calculate the reliability and optimal features for each type of non-finite States. So far , a separate algorithm has been implemented that automatically counts paired non-finite states, and a completely different algorithm that counts triple non-finite states. This option is not suitable. I need to somehow create an algorithm that will count the reliability and optimal features at each step without changing the logic of building the program.
Here is the code:
A = [1 1 1 1 1;
1 2 1 2 1;
2 2 1 1 2;
2 1 1 3 2;
2 2 2 3 1;
1 3 2 2 2];% input of source data (matrix, rows of which are the technical States of the object, columns-features that are used for recognition of the technical state)
ProbabilityMatrix=[0.5 0.09 0.06 0.12 0.15 0.08];% setting the probability values for end States
PsuccesAlpha=[0.012 0.03 0.07 0.02 0.01];% entering alpha values(errors of the first kind)
PsuccesBeta=[0.02 0.05 0.08 0.03 0.008];% entering beta values(second-kind errors)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[M,N]=size(A);%determining the size of the source matrix
ComparisonRes=cell(1,M-2);% creating an array of cells with a dimension that matches the size of possible non-finite States
for NumberOfComparison=2:M-1 %value that defines the length of the non-final state ( for example, NumberOfComparison=2 - SiSj;NumberOfComparison=5 - SiSjSkSlSm...)
indices_bounds = zeros(1,NumberOfComparison); % zero vector with the number of columns equal to NumberOfComparison
indices_bounds(1:NumberOfComparison)=M; % filling the indices_bonds elements with the value of the number of possible end States for each feature ( i.e. - 6 6 6 6 6 6 because there are 6 different States)
length_indices_bounds=length(indices_bounds);% determining the length of a vectorindices_bounds
CriterialMassive = cell(prod(indices_bounds), numel(indices_bounds)+3); % creating an array of cells whose dimension means: number of rows - the number of possible combinations of States for all attributes (6*6*6*6*6);number of columns - 5 for features +3 for confidence value, optimal feature, logical comparison
CriterialVector=zeros(prod(indices_bounds), numel(indices_bounds)+1);% creating a vector to record the result of comparing strings with each other
tick=1;
B=cell(1,length_indices_bounds);% creating a cell vector
for linearindex = 1 : prod(indices_bounds)
[B{:}]=ind2sub(indices_bounds, linearindex);%ind2sub - a command that fills in a vector, so (in square brackets) generating all possible combinations
if sum([B{2:length_indices_bounds}]-[B{1:length_indices_bounds-1}]>0)==length_indices_bounds-1 % condition for checking suitable indexes, since only rows with numbers are compared to discard unnecessary comparisons
%I>J>k>...M
[CriterialMassive{tick,1:numel(indices_bounds)}] = ind2sub(indices_bounds, linearindex);%Record the indexes of the strings being compared
CheckMatrix=A([B{1:length_indices_bounds}],:);%Create a matrix for the comparison of States on the grounds
CheckMatrixWithInverseElements=CheckMatrix.^(-1); %Inverting elements of the comparison matrix
for i=1:N
CriterialVector(tick,i)=...
sum(CheckMatrix(:,i))*sum(CheckMatrixWithInverseElements(:,i))~=length_indices_bounds^2;% sufficient condition for checking the indistinguishability of type attributes
%(а1+a2+...+an)*(1/a1+1/a2+...+1/an)=n^2-only if everyone ai is equal
end
CriterialMassive{tick,numel(indices_bounds)+1}=CriterialVector(tick,:);%Recording the result of string comparison
tick=tick+1;%updating the tag
else
CriterialVector(tick,:)=[];%Deleting the corresponding row because the combination of indexes is not allowed
CriterialMassive(tick,:)=[];%Deleting the corresponding row because the combination of indexes is not allowed
end
end
ComparisonRes{NumberOfComparison-1}=CriterialMassive;%ЗEntry in NumberOfComparison-1st element of the array of comparisons by NumberOfComparison strings
end
%Processing the SiSj non-finite conditions
for i=1:nchoosek(M,2)% this loop fills ComparisonRes{1}, that is, cells that store information for non-finite States of the form Si Sj, the number of which is equal to the number of combinations of them M by 2
J=ComparisonRes{1}{i,1};% the first index of a possible combination ( the first final state in a double non-finite)
I=ComparisonRes{1}{i,2};% the second index of a possible combination ( the second final state in a double non-finite)
Prob=ProbabilityMatrix(J)+ProbabilityMatrix(I); % the sum of the probabilities of these double States
Probability(i,1)=ProbabilityMatrix(J)/Prob;% finding the probability of the first hypothesis of two, which allows you to recognize a non-final state consisting of two, into two final States
Probability(i,2)=ProbabilityMatrix(I)/Prob;% finding the probability of the second hypothesis of two, which allows you to recognize a non-final state consisting of two, into two final States
Pindex=find(ComparisonRes{1}{i,3}==1);% finding in a logical comparison of two rows of units that make sense of the distinguishability of States by a specific feature
D{i}=zeros(1,length(Pindex));% creating a preliminary null vector for entering confidence values in it
for j=1:length(Pindex)% loop for calculating confidence values
D{i}(j)=max(Probability(i,1),Probability(i,2))*(1-PsuccesAlpha(Pindex(j)))+...
min(Probability(i,1),Probability(i,2))*(1-PsuccesBeta(Pindex(j)));
% the value of reliability is determined by multiplying the probability of the main hypothesis
%on the error of the first kind, and competing on the error of the second kind
%( and the main one is the hypothesis whose probability is greater than competing - whose probability is smaller
%when the equality of the probabilities necessary to analyze price check and choose the basis where the price is less)
end
ComparisonRes{1}{i,5}=Pindex(D{i}==max(D{i}(:)));% filling in the fifth column with the optimal feature for recognition
ComparisonRes{1}{i,4}=max(D{i}(:));% filling in the fourth column with the confidence value ( the maximum among the calculated values)
end
%Processing the SiSjSm non-finite conditions
MassiveForThreeConditions = cell(nchoosek(M,3),5);% it will contain cells that store information on triple non-final States
Condition=cell(1,3);% an array of cells for the formation of the triple States
for i=1:nchoosek(M,3)
[Condition{:}]=ComparisonRes{2}{i,1:3};%filling the array with possible non-final States of thre
CombineTwoConditions = nchoosek([Condition{:}],2);%creating for each triple state a set of combinations of 2 of the indexes taken in the triple state
AllCombinationsOfTwo=cell2mat(ComparisonRes{1});% converting an array of ComparisonRes{1} cells to a matrix, i.e. getting a matrix containing information on dual States
AllCombinationsOfTwo(:,3:9)=[];% deleting columns that have no value for further actions (leaving only combinations of 2 elements)
NumberOfLine=zeros(1,nchoosek(3,2));%line numbers in the entire list of combinations of 2 States that belong to a specific state
for j=1:nchoosek(3,2)
NumberOfLine(j)=find(sum(AllCombinationsOfTwo-CombineTwoConditions(j,:)>0|AllCombinationsOfTwo-CombineTwoConditions(j,:)<0,2)==0);% filling the NumberOfLine vector with line number values for specific combinations of 2 in the entire list of double States
end
MassiveForThreeConditions{i,1}= CombineTwoConditions;% contains double combinations of the triple state
MassiveForThreeConditions{i,2}=NumberOfLine.'; %contains line numbers in ComparisonRes
C=cell2mat(ComparisonRes{1});
CAT=cat(1,C(NumberOfLine,3:7));% combining logical comparisons that belong to three combinations of two elements into a single matrix
MassiveForThreeConditions{i,3}= CAT;% filling the third column of the array with logical comparisons of three double States
%to determine the separation of a triple state
SumProbability=sum(ProbabilityMatrix([Condition{:}]));% calculating the sum of probabilities
for j=1:N% a loop for searching for triple States that can be distinguished by some feature
ZeroInd=find(MassiveForThreeConditions{i,3}(:,j)==0);
if isempty(ZeroInd)%If all three States are distinguishable
D4=zeros(1,3);% vector for calculating the confidence value
for m=1:3% a loop for calculating the probability values of triple States, which can be distinguished into three final States by some feature. The peculiarity is that we can not consider three hypotheses, since this criterion does not allow, so we consider two hypotheses, one of them is the final state, the other is the Union of two non - finite ones
ProbabilityOfDoubleCond=sum(ProbabilityMatrix(MassiveForThreeConditions{i,1}(m,:)))/...% calculating the probability of one of the hypotheses (contains the probability of a double state)
ProbabilityOfOneCond==1-ProbabilityOfDoubleCond;% calculating the probability of the second hypothesis. Since 2 hypotheses form a complete group of events, the probability value of the second hypothesis can be found by subtracting the probability of the first hypothesis from the 1
if ProbabilityOfDoubleCond>ProbabilityOfOneCond% determination of the main and competing hypotheses and confidence calculation
D4(m)=ProbabilityOfDoubleCond*(1-PsuccesAlpha(j))*...% the calculation of reliability, if the primary hypothesis is the double condition
ComparisonRes{1}{MassiveForThreeConditions{i,2}(m),4}+...
ProbabilityOfOneCond*(1-PsuccesBeta(j));
else
D4(m)=ProbabilityOfOneCond*(1-PsuccesAlpha(j))+...% confidence calculation if the main hypothesis is the final state
ProbabilityOfDoubleCond*(1-PsuccesBeta(j))*...
ComparisonRes{1}{MassiveForThreeConditions{i,2}(m),4};
end
end
D3{i}(j)=sum(D4)/3;% the overall confidence will be averaged
elseif length(ZeroInd)==1%If two States are indistinguishable from each other, and 3 is distinguishable from each. In this case, the division into hypotheses occurs in a different way from the previous one. Since the triple state is divided into one finite and one non-finite consisting of two, we take the final state for the first hypothesis, and the double state for the second hypothesis
ProbabilityOfDoubleCond=sum(ProbabilityMatrix(MassiveForThreeConditions{i,1}(ZeroInd,:)))/SumProbability;% calculating the probability of one of the hypotheses (contains the probability of a double state)
ProbabilityOfOneCond=1-ProbabilityOfDoubleCond;% calculating the probability of the second hypothesis
if ProbabilityOfDoubleCond>ProbabilityOfOneCond %determination of the main and competing hypotheses and confidence calculation
D3{i}(j)=ProbabilityOfDoubleCond*(1-PsuccesAlpha(j))*...% the calculation of reliability, if the primary hypothesis is the double condition
ComparisonRes{1}{MassiveForThreeConditions{i,2}(ZeroInd),4}+...
ProbabilityOfOneCond*(1-PsuccesBeta(j));
else
D3{i}(j)=ProbabilityOfOneCond*(1-PsuccesAlpha(j))+...% confidence calculation if the main hypothesis is the final state
ProbabilityOfDoubleCond*(1-PsuccesBeta(j))*...
ComparisonRes{1}{MassiveForThreeConditions{i,2}(ZeroInd),4};
end
else %If all three States are indistinguishable
D3{i}(j)=0;
end
end
ComparisonRes{2}{i,5}=max(D3{i}(:));% filling ComparisonRes{2} with confidence
ComparisonRes{2}{i,6}=find(D3{i}==max(D3{i}(:)));% filling ComparisonRes{2} with optimal checks
end
So, if anyone can offer a technical solution for this problem I'll appreciate this, because I don't have any ideas how to automatically create the logical states and distinguish the non-finite conditions of the system.

回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by