You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CombineDataWithAttributes.m 1.0KB

5 years ago
1234567891011121314151617181920212223242526272829303132333435
  1. function [dataWithAtt, totalAttNum] = CombineDataWithAttributes(data, attributes, attUpperRange, attWeight)
  2. totalAttNum = sum(attUpperRange);
  3. sizeWithAtt = totalAttNum + size(data,1);
  4. dataWithAtt = zeros(sizeWithAtt, sizeWithAtt);
  5. dataWithAtt(totalAttNum+1:end,totalAttNum+1:end) = data;
  6. numAttTypes = size(attUpperRange,2);
  7. attOffsets = zeros(numAttTypes);
  8. nodeOffset = totalAttNum;
  9. if (numAttTypes>1)
  10. for i=2:numAttTypes
  11. attOffsets(i) = attOffsets(i-1)+attUpperRange(i-1);
  12. end
  13. end
  14. dataLines = size(data,1);
  15. attLines = size(attributes,1);
  16. if (attLines ~= dataLines)
  17. fprintf('CombineDataWithAttributes - Invalid data sizes: data %d, attributes %d\n',dataLines,attLines);
  18. end
  19. for line=1:dataLines
  20. for att=1:numAttTypes
  21. value = attributes(line,att);
  22. if value > 0
  23. dataWithAtt(nodeOffset+line,attOffsets(att)+value)=attWeight;
  24. dataWithAtt(attOffsets(att)+value,nodeOffset+line)=attWeight;
  25. end
  26. end
  27. end
  28. dataWithAtt = sparse(dataWithAtt);