Log In
New Account
  
 
Home My Page Project Tree Code Snippets Project Openings NUTSS
 
 
Summary Tracker Lists CVS Files
 

CVS | Administration

Annotation of libnutss/examples/process_data.m, revision 1.3

1.1       ths         1: function re = process_data(sampleclocks)
                      2:
1.3     ! ths         3:     % should be about mincapacity/mindegree
1.1       ths         4:     capacityPerPeer = 400;
                      5:
                      6:     fid = fopen('args.txt','r');
                      7:     n = fscanf(fid,'nodes: %d\n',1);
                      8:     fclose(fid);
                      9:     capacities = zeros(1,n);
                     10:     peers = zeros(n,1);
1.3     ! ths        11:     peertimes = zeros(n,1);
1.2       ths        12:     lengths = zeros(n,1);
1.3     ! ths        13:     lengthtimes = zeros(n,1);
        !            14:     capoverpeer = zeros(1,n);
1.1       ths        15:     rejections = zeros(n,1);
                     16:     retirations = zeros(n,1);
1.3     ! ths        17:     retirebucket = zeros(60,1);
        !            18:     freecapacity = zeros(n,1);
        !            19:     freecapacitytimes = zeros(n,1);
1.1       ths        20:     f = cell(1,n);
                     21:     % read the files, get all the data organized
                     22:     for i=1:n
                     23:         fid=fopen(['peer_node' num2str(i) '.txt'],'r');
                     24:         if(fid > 0)
                     25:            numpeers = fscanf(fid,'%d %d');
1.3     ! ths        26:            peers(i,1:length(numpeers(2:2:end))) = numpeers(2:2:end);
        !            27:            peertimes(i,1:length(numpeers(1:2:end))) = numpeers(1:2:end);
1.1       ths        28:            fclose(fid);
                     29:         end
                     30:     end
                     31:     for i=1:n
1.2       ths        32:         fid=fopen(['walk_node' num2str(i) '.txt'],'r');
                     33:         if(fid > 0)
                     34:            walk = fscanf(fid,'%d %d');
1.3     ! ths        35:            lengths(i,1:length(walk(2:2:end))) = walk(2:2:end);
        !            36:            lengthtimes(i,1:length(walk(1:2:end))) = walk(1:2:end);
1.2       ths        37:            fclose(fid);
                     38:         end
1.3     ! ths        39:     end
1.2       ths        40:     for i=1:n
1.1       ths        41:         fid=fopen(['data_node' num2str(i) '.txt'],'r');
                     42:         if(fid > 0)
                     43:             cap = fscanf(fid,'%d',1);
                     44:             if length(cap) > 0
                     45:                 capacities(i) = cap;
                     46:             else
                     47:                 continue;
                     48:             end
                     49:             t = textscan(fid,'%d%s');
                     50:             m = length(t{1});
                     51:             times = []; weights = [];
                     52:             durations = [];
                     53:             for j=1:m
                     54:                 if(strcmp(t{2}{j},'reject'))
                     55:                     rejections(i,j) = t{1}(j);
                     56:                 elseif(strcmp(t{2}{j},'retire'))
1.3     ! ths        57:                     curminute = floor(t{1}(j) / 60);
        !            58:                     retirebucket(curminute) = retirebucket(curminute)+1;
1.1       ths        59:                     retirations(i,j) = t{1}(j);
                     60:                 else
                     61:                     data = sscanf(t{2}{j},'%d;%d;%d;');
                     62:                     if(length(data) > 0)
                     63:                         times = [times t{1}(j)];
                     64:                         durations = [durations data(1)];
                     65:                         weights = [weights data(2)];
                     66:                     end
                     67:                 end
                     68:             end
                     69:             f{i} = [times;durations;weights];
                     70:             fclose(fid);
                     71:         end
                     72:     end
1.2       ths        73:     f1 = figure(); axes(); title('Load Versus Time');
1.1       ths        74:     xlabel('Time (m)'); ylabel('Load'); hold on;
                     75:     d = zeros(n,1); m = zeros(n,1); s = zeros(n,1);
                     76:     samples = zeros(n,1); sampletimes = zeros(n,1);
1.2       ths        77: %     f2 = figure(); axes(); title('Relative Load Versus Time');
                     78: %     xlabel('Time (m)'); ylabel('Load / Capacity'); hold on;
                     79: %     d = zeros(n,1); m = zeros(n,1); s = zeros(n,1);
                     80: %     samples = zeros(n,1); sampletimes = zeros(n,1);
1.1       ths        81:
                     82:     first_denial = min(retirations(find(retirations > 0)));
                     83:     if length(first_denial) > 0
                     84:         sampleclocks = [first_denial(1)/60 sampleclocks];
                     85:     end
                     86:     % reconstruct load over time from recorded events
                     87:     for i=1:n
                     88:         if(length(f{i}) > 0)
                     89:             rqsts = length(f{i}(1,:));
                     90:             times = zeros(1,rqsts*2);
                     91:             delta = zeros(1,rqsts*2);
                     92:             k = 1;
                     93:             for j=1:rqsts
                     94:                 times(k) = f{i}(1,j);
                     95:                 delta(k) = f{i}(3,j);
                     96:                 times(k+1) = f{i}(1,j)+f{i}(2,j);
                     97:                 delta(k+1) = -f{i}(3,j);
                     98:                 k = k + 2;
                     99:             end
                    100:             [sortedtimes,permutation]=sort(times./60);
                    101:             d(i,1:2*rqsts) = cumsum(delta(permutation));
1.3     ! ths       102:
        !           103:             freecapacity(i,1:2*rqsts) = capacities(i)-d(i,1:2*rqsts);
        !           104:             freecapacitytimes(i,1:2*rqsts) = sortedtimes;
        !           105:
        !           106:             mypeers = [];
        !           107:             for ii=1:length(sortedtimes)
        !           108:                 % find closest timestep
        !           109:                 newmin = inf;
        !           110:                 for jj=1:length(peertimes(i,:))
        !           111:                     mine = inf;
        !           112:                     if sortedtimes(ii)*60 > 0 && peertimes(i,jj) > 0 && ...
        !           113:                        abs(sortedtimes(ii)*60-peertimes(i,jj)) < newmin
        !           114:                         newmin = abs(sortedtimes(ii)*60-peertimes(i,jj));
        !           115:                         mine = peers(i,jj);
        !           116:                     end
        !           117:                 end
        !           118:                 mypeers = [mypeers mine];
        !           119:             end
        !           120:             nonzp = peers(i,find(peers(i,:)));
        !           121:             capoverpeer(1:length(nonzp),i) = capacities(i)./nonzp';
1.1       ths       122:             %%
                    123:             if(length(sortedtimes(find(d(i,:) > capacities(i)))) > 0)
                    124:                 i
                    125:             end
                    126:             %%
                    127:             m(i) = mean(d(i,1:2*rqsts));
                    128:             s(i) = std(d(i,1:2*rqsts));
1.2       ths       129:             figure(f1);
1.1       ths       130:             plot(sortedtimes,d(i,1:2*rqsts));
                    131:             temp = rejections(i,find(rejections(i,:)))./60;
                    132:             plot(temp,ones(size(temp))*capacities(i),'g*');
                    133:             temp = retirations(i,find(retirations(i,:)))./60;
                    134:             plot(temp,ones(size(temp))*capacities(i),'r*');
1.2       ths       135: %             figure(f2);
                    136: %             plot(sortedtimes,d(i,1:2*rqsts)./capacities(i));
1.1       ths       137:             k = 1;
                    138:             for sampleclock=sampleclocks
                    139:                 temp = abs(sortedtimes-sampleclock);
                    140:                 samp = find(min(temp)==temp);
                    141:                 sample(i,k) = d(i,samp(1));
                    142:                 sampletimes(i,k) = sortedtimes(samp(1));
                    143:                 k = k + 1;
                    144:                 % this code below plots load with no gradation, the way it
                    145:                 % works otherwise is as if load grows and shrinks gradually
                    146:                 % rather than incrementally, this makes it completely discrete
                    147:     %             temp = zeros(1,3*rqsts+1);
                    148:     %             temptimes = zeros(1,3*rqsts);
                    149:     %             get = 1;
                    150:     %             temptimes(1) = sortedtimes(get);
                    151:     %             for put=1:2:3*rqsts
                    152:     %                 temp(put) = d(i,get);
                    153:     %                 temp(put+1) = d(i,get);
                    154:     %                 temptimes(put+1) = sortedtimes(get);
                    155:     %                 temptimes(put+2) = sortedtimes(get);
                    156:     %                 get = get+1;
                    157:     %             end
                    158:
                    159:     %             points = min(length(temp),length(temptimes));
                    160:     %             plot(temptimes(1:points),temp(1:points));
                    161:             end
                    162:         end
                    163:     end
                    164:     hold off;
1.3     ! ths       165: %{
        !           166:     freecapbucket = zeros(1,60);
        !           167:
        !           168:     for i=1:n
        !           169:         buckets = zeros(2,60);
        !           170:         for j=1:length(freecapacity)
        !           171:            curminute = floor(freecapacitytimes(i,j));
        !           172:            buckets(1,curminute+1) = buckets(1,curminute+1)+freecapacity(i,j);
        !           173:            buckets(2,curminute+1) = buckets(2,curminute+1)+1;
        !           174:         end
        !           175:         freecapbucket = freecapbucket + buckets(1,:)./buckets(2,:);
        !           176:         freecapbucket(find(isnan(freecapbucket))) = 0;
        !           177:     end
        !           178:   %}
        !           179:     tot = 0;
        !           180:     num = 0;
        !           181:     freecapbucket = zeros(1,length(freecapacity));
        !           182:     numalive = zeros(1,length(freecapacity));
        !           183:     for j=1:length(freecapacity)
        !           184:         tot = 0;
        !           185:         num = 0;
        !           186:         for i=1:n
        !           187:             if freecapacity(i,j) > 0
        !           188:                 tot = tot + freecapacity(i,j);
        !           189:                 num = num + 1;
        !           190:             end
        !           191:         end
        !           192:         freecapbucket(j) = tot / num;
        !           193:         numalive(j) = num;
        !           194:     end
        !           195:
        !           196:     figure();
        !           197:     title('average free capacity vs time');
        !           198:     hold on;
        !           199:     plot((1:length(freecapacity))./8,freecapbucket);
        !           200:     hold off;
        !           201:     figure();
        !           202:     title('rejections per minute');
        !           203:     hold on;
        !           204:     plot(retirebucket);
        !           205:     hold off;
        !           206:     figure();
        !           207:     title('num alive');
        !           208:     hold on;
        !           209:     plot(numalive);
        !           210:     hold off;
        !           211:
        !           212:     t = length(capoverpeer(:,1));
        !           213:     md = zeros(1,t);
        !           214:     for i=1:t
        !           215:         sn = capoverpeer(i,:);
        !           216:         md(i) = mean(abs(sn(find(sn))-capacityPerPeer));
        !           217:     end
        !           218:     figure();
        !           219:     title('mean capacity / peer');
        !           220:     hold on;
        !           221:     plot((1:t)./8,md)
        !           222:     hold off;
1.2       ths       223:
1.3     ! ths       224:     figure();
        !           225:     xlabel('Time (min)'); ylabel('Capacity / Peers');
        !           226:     title('Comparison of Capacity / Peers Ratio to Optimal');
        !           227:     for i=1:n
        !           228:         if i == 1
        !           229:             hold on;
        !           230:             plot(1:round(t/8),capacityPerPeer*ones(1,round(t/8)),'r')
        !           231:             hold off;
        !           232:         end
        !           233:         hold on;
        !           234:         cpop = capoverpeer(:,i);
        !           235:         plot((1:length(find(cpop)))./8,cpop(find(cpop)));
        !           236:         hold off;
        !           237:     end
1.2       ths       238:
                    239:
1.3     ! ths       240: %{
1.1       ths       241:     for k=1:length(sampleclocks)
                    242: %         figure(); axes(); title(['Distribution of Load per Peer at ' num2str(sampleclocks(k)) ' Minutes']);
                    243: %         xlabel('Load per Peer'); ylabel('Number of Nodes'); hold on;
                    244: %         hist(sample(:,k)'./peers,35); hold off;
                    245: %         figure(); axes(); title(['Relative Load at ' num2str(sampleclocks(k)) ' Minutes']);
                    246: %         xlabel('Node'); ylabel('Percent Load'); hold on;
                    247: %         bar(sample(:,k)'./peers./capacityPerPeer.*100); hold off;
                    248:         figure(); axes(); title(['Sorted Relative Load at ' num2str(sampleclocks(k)) ' Minutes']);
                    249:         xlabel('Node'); ylabel('Percent Load'); hold on;
1.2       ths       250:         loads = sort(sample(:,k)'./capacities(1:length(sample(:,k)')).*100);
1.1       ths       251:      bar(loads(find(~isnan(loads) & loads ~= 0))); hold off;
                    252:         % also show loads sorted by capacity
                    253:         figure(); axes(); title(['Relative Load at ' num2str(sampleclocks(k)) ' Minutes Sorted by Capacity']);
                    254:         xlabel('Node (Capacities Low to High)'); ylabel('Percent Load'); hold on;
1.2       ths       255:         [garbage,permu] = sort(capacities(1:length(sample(:,k)')),'ascend');
                    256:         loads = (sample(:,k)'./capacities(1:length(sample(:,k)')).*100);
1.1       ths       257:         loads = loads(permu);
                    258:         bar(loads(find(~isnan(loads) & loads ~= 0))); hold off;
                    259:     end
1.3     ! ths       260: %}
        !           261:
1.2       ths       262: %{
1.1       ths       263:     return;
1.2       ths       264:
1.1       ths       265:     [n,t] = size(peers);
                    266:     f1 = figure(); f2 = figure();
                    267:     for i=1:n
                    268:         times = [];
                    269:         degree = [];
                    270:         mypeers = [];
                    271:         for k=2:2:t
                    272:             if peers(i,k) > 0
                    273:                 mypeers(k/2) = peers(i,k);
                    274:                 degree(k/2) = capacities(i) / peers(i,k);
                    275:                 times(k/2) = peers(i,k-1) / 60;
                    276:             else
                    277:                 break;
                    278:             end
                    279:         end
                    280:         figure(f1);
                    281:         plot(times,degree);
                    282:         axis([0 45 0 1200]);
                    283:         title(['Node ' num2str(i) ' Capacity ' num2str(capacities(i))]);
                    284:         xlabel('Time'); ylabel('Capacity / Peer');
                    285:         figure(f2);
                    286:         plot(times,mypeers);
                    287:         axis([0 45 0 42]);
                    288:         title(['Node ' num2str(i) ' Capacity ' num2str(capacities(i))]);
                    289:         xlabel('Time'); ylabel('Peers');
1.2       ths       290: end
1.3     ! ths       291:
1.2       ths       292:     [n,t] = size(lengths);
                    293:     f1 = figure();
                    294:     title([' Extensions versus Time']);
                    295:     xlabel('Time'); ylabel('Extensions');
                    296:     for i=1:n
                    297:         times = [];
                    298:         mylengths = [];
                    299:         for k=2:2:t
                    300:             if lengths(i,k) > 0
                    301:                 mylengths(k/2) = lengths(i,k);
                    302:                 times(k/2) = lengths(i,k-1) / 60;
                    303:             else
                    304:                 break;
                    305:             end
                    306:         end
                    307: %        figure(f1);
                    308:         hold on;
                    309:         plot(times,mylengths);
                    310:         hold off;
1.1       ths       311:     end
1.3     ! ths       312: %}
1.1       ths       313: %     figure(); axes(); title('Distribution of Mean Load');
                    314: %     xlabel('Mean Load'); ylabel('Nodes'); hold on;
                    315: %     hist(m,35); hold off;
                    316: %     figure(); axes(); title('Distribution of Standard Deviation of Load');
                    317: %     xlabel('Standard Deviation of Load'); ylabel('Nodes'); hold on;
                    318: %     hist(s,35); hold off;
                    319: end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
 

GForge.cis.cornell.edu is brought to you by

Cornell Computing and Information Science


Powered By GForge Collaborative Development Environment