added SAX, final reports skeletons, screenshots
This commit is contained in:
parent
c15f893e47
commit
ac791ce418
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
obj_*
|
||||
*~
|
||||
code.pdf
|
||||
*~
|
BIN
Coursework-Reports/NonSaxAggregate.png
Normal file
BIN
Coursework-Reports/NonSaxAggregate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
BIN
Coursework-Reports/NonSaxWithRed.png
Normal file
BIN
Coursework-Reports/NonSaxWithRed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
BIN
Coursework-Reports/SaxBy2,10Break.png
Normal file
BIN
Coursework-Reports/SaxBy2,10Break.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
BIN
Coursework-Reports/SaxBy4,8Break.png
Normal file
BIN
Coursework-Reports/SaxBy4,8Break.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
@ -150,6 +150,21 @@ lstparams "breaklines=true,frame=tb,language=C,basicstyle={\\ttfamily},commentst
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
\begin_inset CommandInset include
|
||||
LatexCommand lstinputlisting
|
||||
filename "../Coursework/sax.h"
|
||||
lstparams "breaklines=true,frame=tb,language=C,basicstyle={\\ttfamily},commentstyle={\\color{commentgreen}\\itshape},keywordstyle={\\color{blue}},emphstyle={\\color{red}},stringstyle={\\color{red}},identifierstyle={\\color{cyan}},caption={SAX header file: z-normalise and stringify buffers}"
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\begin_inset Newpage pagebreak
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
|
BIN
Coursework-Reports/code.pdf
Normal file
BIN
Coursework-Reports/code.pdf
Normal file
Binary file not shown.
169
Coursework-Reports/report.lyx
Normal file
169
Coursework-Reports/report.lyx
Normal file
@ -0,0 +1,169 @@
|
||||
#LyX 2.3 created this file. For more info see http://www.lyx.org/
|
||||
\lyxformat 544
|
||||
\begin_document
|
||||
\begin_header
|
||||
\save_transient_properties true
|
||||
\origin unavailable
|
||||
\textclass article
|
||||
\begin_preamble
|
||||
\usepackage{color}
|
||||
|
||||
\definecolor{commentgreen}{RGB}{0,94,11}
|
||||
\end_preamble
|
||||
\use_default_options true
|
||||
\begin_modules
|
||||
customHeadersFooters
|
||||
\end_modules
|
||||
\maintain_unincluded_children false
|
||||
\language english
|
||||
\language_package default
|
||||
\inputencoding auto
|
||||
\fontencoding global
|
||||
\font_roman "default" "default"
|
||||
\font_sans "default" "default"
|
||||
\font_typewriter "default" "default"
|
||||
\font_math "auto" "auto"
|
||||
\font_default_family default
|
||||
\use_non_tex_fonts false
|
||||
\font_sc false
|
||||
\font_osf false
|
||||
\font_sf_scale 100 100
|
||||
\font_tt_scale 100 100
|
||||
\use_microtype false
|
||||
\use_dash_ligatures true
|
||||
\graphics default
|
||||
\default_output_format default
|
||||
\output_sync 0
|
||||
\bibtex_command default
|
||||
\index_command default
|
||||
\paperfontsize default
|
||||
\spacing single
|
||||
\use_hyperref true
|
||||
\pdf_title "IoT Aggregation Algorithm Coursework"
|
||||
\pdf_author "Andy Pack"
|
||||
\pdf_subject "IoT"
|
||||
\pdf_bookmarks true
|
||||
\pdf_bookmarksnumbered false
|
||||
\pdf_bookmarksopen false
|
||||
\pdf_bookmarksopenlevel 1
|
||||
\pdf_breaklinks true
|
||||
\pdf_pdfborder true
|
||||
\pdf_colorlinks false
|
||||
\pdf_backref false
|
||||
\pdf_pdfusetitle true
|
||||
\papersize default
|
||||
\use_geometry true
|
||||
\use_package amsmath 1
|
||||
\use_package amssymb 1
|
||||
\use_package cancel 1
|
||||
\use_package esint 1
|
||||
\use_package mathdots 1
|
||||
\use_package mathtools 1
|
||||
\use_package mhchem 1
|
||||
\use_package stackrel 1
|
||||
\use_package stmaryrd 1
|
||||
\use_package undertilde 1
|
||||
\cite_engine basic
|
||||
\cite_engine_type default
|
||||
\biblio_style plain
|
||||
\use_bibtopic false
|
||||
\use_indices false
|
||||
\paperorientation portrait
|
||||
\suppress_date false
|
||||
\justification true
|
||||
\use_refstyle 1
|
||||
\use_minted 0
|
||||
\index Index
|
||||
\shortcut idx
|
||||
\color #008000
|
||||
\end_index
|
||||
\leftmargin 1cm
|
||||
\topmargin 1.5cm
|
||||
\rightmargin 1cm
|
||||
\bottommargin 1.5cm
|
||||
\secnumdepth 3
|
||||
\tocdepth 3
|
||||
\paragraph_separation indent
|
||||
\paragraph_indentation default
|
||||
\is_math_indent 0
|
||||
\math_numbering_side default
|
||||
\quotes_style english
|
||||
\dynamic_quotes 0
|
||||
\papercolumns 1
|
||||
\papersides 1
|
||||
\paperpagestyle fancy
|
||||
\tracking_changes false
|
||||
\output_changes false
|
||||
\html_math_output 0
|
||||
\html_css_as_file 0
|
||||
\html_be_strict false
|
||||
\end_header
|
||||
|
||||
\begin_body
|
||||
|
||||
\begin_layout Left Header
|
||||
IoT Aggregation Algorithm Coursework
|
||||
\end_layout
|
||||
|
||||
\begin_layout Left Footer
|
||||
November 2020
|
||||
\end_layout
|
||||
|
||||
\begin_layout Right Footer
|
||||
Andy Pack / 6420013
|
||||
\end_layout
|
||||
|
||||
\begin_layout Section
|
||||
Description
|
||||
\end_layout
|
||||
|
||||
\begin_layout Section
|
||||
Specification
|
||||
\end_layout
|
||||
|
||||
\begin_layout Section
|
||||
Implementation
|
||||
\end_layout
|
||||
|
||||
\begin_layout Section
|
||||
Output
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
\begin_inset Float figure
|
||||
placement h
|
||||
wide false
|
||||
sideways false
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
\align center
|
||||
\begin_inset Graphics
|
||||
filename SaxBy2,10Break.png
|
||||
width 100col%
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
\begin_inset Caption Standard
|
||||
|
||||
\begin_layout Plain Layout
|
||||
Demonstration of SAX aggregation with window size of 2 and alphabet of length
|
||||
10
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_body
|
||||
\end_document
|
BIN
Coursework-Reports/report.pdf
Normal file
BIN
Coursework-Reports/report.pdf
Normal file
Binary file not shown.
222
Coursework-Reports/screenshot.lyx
Normal file
222
Coursework-Reports/screenshot.lyx
Normal file
@ -0,0 +1,222 @@
|
||||
#LyX 2.3 created this file. For more info see http://www.lyx.org/
|
||||
\lyxformat 544
|
||||
\begin_document
|
||||
\begin_header
|
||||
\save_transient_properties true
|
||||
\origin unavailable
|
||||
\textclass article
|
||||
\begin_preamble
|
||||
\usepackage{color}
|
||||
|
||||
\definecolor{commentgreen}{RGB}{0,94,11}
|
||||
\end_preamble
|
||||
\use_default_options true
|
||||
\begin_modules
|
||||
customHeadersFooters
|
||||
\end_modules
|
||||
\maintain_unincluded_children false
|
||||
\language english
|
||||
\language_package default
|
||||
\inputencoding auto
|
||||
\fontencoding global
|
||||
\font_roman "default" "default"
|
||||
\font_sans "default" "default"
|
||||
\font_typewriter "default" "default"
|
||||
\font_math "auto" "auto"
|
||||
\font_default_family default
|
||||
\use_non_tex_fonts false
|
||||
\font_sc false
|
||||
\font_osf false
|
||||
\font_sf_scale 100 100
|
||||
\font_tt_scale 100 100
|
||||
\use_microtype false
|
||||
\use_dash_ligatures true
|
||||
\graphics default
|
||||
\default_output_format default
|
||||
\output_sync 0
|
||||
\bibtex_command default
|
||||
\index_command default
|
||||
\paperfontsize default
|
||||
\spacing single
|
||||
\use_hyperref true
|
||||
\pdf_title "IoT Aggregation Algorithm Coursework"
|
||||
\pdf_author "Andy Pack"
|
||||
\pdf_subject "IoT"
|
||||
\pdf_bookmarks true
|
||||
\pdf_bookmarksnumbered false
|
||||
\pdf_bookmarksopen false
|
||||
\pdf_bookmarksopenlevel 1
|
||||
\pdf_breaklinks true
|
||||
\pdf_pdfborder true
|
||||
\pdf_colorlinks false
|
||||
\pdf_backref false
|
||||
\pdf_pdfusetitle true
|
||||
\papersize default
|
||||
\use_geometry true
|
||||
\use_package amsmath 1
|
||||
\use_package amssymb 1
|
||||
\use_package cancel 1
|
||||
\use_package esint 1
|
||||
\use_package mathdots 1
|
||||
\use_package mathtools 1
|
||||
\use_package mhchem 1
|
||||
\use_package stackrel 1
|
||||
\use_package stmaryrd 1
|
||||
\use_package undertilde 1
|
||||
\cite_engine basic
|
||||
\cite_engine_type default
|
||||
\biblio_style plain
|
||||
\use_bibtopic false
|
||||
\use_indices false
|
||||
\paperorientation portrait
|
||||
\suppress_date false
|
||||
\justification true
|
||||
\use_refstyle 1
|
||||
\use_minted 0
|
||||
\index Index
|
||||
\shortcut idx
|
||||
\color #008000
|
||||
\end_index
|
||||
\leftmargin 1cm
|
||||
\topmargin 1.5cm
|
||||
\rightmargin 1cm
|
||||
\bottommargin 1.5cm
|
||||
\secnumdepth 3
|
||||
\tocdepth 3
|
||||
\paragraph_separation indent
|
||||
\paragraph_indentation default
|
||||
\is_math_indent 0
|
||||
\math_numbering_side default
|
||||
\quotes_style english
|
||||
\dynamic_quotes 0
|
||||
\papercolumns 1
|
||||
\papersides 1
|
||||
\paperpagestyle fancy
|
||||
\tracking_changes false
|
||||
\output_changes false
|
||||
\html_math_output 0
|
||||
\html_css_as_file 0
|
||||
\html_be_strict false
|
||||
\end_header
|
||||
|
||||
\begin_body
|
||||
|
||||
\begin_layout Left Header
|
||||
IoT Aggregation Algorithm Coursework
|
||||
\end_layout
|
||||
|
||||
\begin_layout Left Footer
|
||||
November 2020
|
||||
\end_layout
|
||||
|
||||
\begin_layout Right Footer
|
||||
Andy Pack / 6420013
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
\begin_inset Float figure
|
||||
wide false
|
||||
sideways false
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
\align center
|
||||
\begin_inset Graphics
|
||||
filename NonSaxAggregate.png
|
||||
width 100col%
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
\begin_inset Caption Standard
|
||||
|
||||
\begin_layout Plain Layout
|
||||
Demonstration of 4-into-1 aggregation taking place following moderate activity
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
\begin_inset Float figure
|
||||
wide false
|
||||
sideways false
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
\align center
|
||||
\begin_inset Graphics
|
||||
filename NonSaxWithRed.png
|
||||
width 100col%
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
\begin_inset Caption Standard
|
||||
|
||||
\begin_layout Plain Layout
|
||||
Demonstration of both no aggregation for high activity (First output) and
|
||||
tight 12-into-1 average for little activity (Last output), red LED on as
|
||||
aggregation occurs
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
\begin_inset Float figure
|
||||
wide false
|
||||
sideways false
|
||||
status open
|
||||
|
||||
\begin_layout Plain Layout
|
||||
\align center
|
||||
\begin_inset Graphics
|
||||
filename SaxBy2,10Break.png
|
||||
width 100col%
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\begin_layout Plain Layout
|
||||
\begin_inset Caption Standard
|
||||
|
||||
\begin_layout Plain Layout
|
||||
Demonstration of SAX aggregation with window size of 2 and alphabet of length
|
||||
10
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_body
|
||||
\end_document
|
BIN
Coursework-Reports/screenshot.pdf
Normal file
BIN
Coursework-Reports/screenshot.pdf
Normal file
Binary file not shown.
@ -44,8 +44,7 @@ aggregateBuffer(Buffer bufferIn, Buffer bufferOut, int groupSize)
|
||||
|
||||
if(requiredGroups > bufferOut.length) // error check
|
||||
{
|
||||
putFloat((float)bufferIn.length/groupSize);
|
||||
printf(" length out buffer required, %i provided\n", bufferOut.length);
|
||||
putFloat((float)bufferIn.length/groupSize); printf(" length out buffer required, %i provided\n", bufferOut.length);
|
||||
return;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,10 +4,13 @@
|
||||
#define SD_THRESHOLD_SOME 400 // some activity, compress above, flatten below
|
||||
#define SD_THRESHOLD_LOTS 1000 // lots of activity, don't aggregate
|
||||
|
||||
#define AGGREGATION_GROUP_SIZE 4 // group size to aggregate (4 in spec)
|
||||
#define AGGREGATION_GROUP_SIZE 2 // group size to aggregate (4 in spec)
|
||||
|
||||
#define INITIAL_STATE true // whether begins running or not
|
||||
|
||||
#define SAX // use sax aggregation and transform instead of simple average aggregation
|
||||
#define SAX_BREAKPOINTS 10 // number of characters to be used
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include <stdio.h> /* For printf() */
|
||||
@ -17,6 +20,7 @@
|
||||
#include "util.h" // for print methods
|
||||
#include "math.h"
|
||||
#include "buffer.h"
|
||||
#include "sax.h"
|
||||
|
||||
static process_event_t event_buffer_full;
|
||||
|
||||
@ -103,7 +107,11 @@ PROCESS_THREAD(aggregator_process, ev, data)
|
||||
|
||||
Buffer fullBuffer = *(Buffer *)data;
|
||||
/*********************/
|
||||
handleBufferRotation(&fullBuffer); // pass by reference, edited if lots of activity
|
||||
#ifdef SAX
|
||||
handleSAXBufferRotation(&fullBuffer);
|
||||
#else
|
||||
handleSimpleBufferRotation(&fullBuffer); // pass by reference, edited if lots of activity
|
||||
#endif
|
||||
freeBuffer(fullBuffer);
|
||||
/*********************/
|
||||
}
|
||||
@ -113,7 +121,7 @@ PROCESS_THREAD(aggregator_process, ev, data)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
// Buffer filled with readings, process and aggregate
|
||||
void
|
||||
handleBufferRotation(Buffer *inBufferPtr)
|
||||
handleSimpleBufferRotation(Buffer *inBufferPtr)
|
||||
{
|
||||
printf("Buffer full, aggregating\n\n");
|
||||
|
||||
@ -153,6 +161,31 @@ handleBufferRotation(Buffer *inBufferPtr)
|
||||
outBuffer.items[0] = sd.mean;
|
||||
}
|
||||
outBuffer.stats = sd; // final compressed buffer has pointer to stats for uncompressed data in case of further interest
|
||||
inBuffer.stats = sd;
|
||||
|
||||
/*********************/
|
||||
handleFinalBuffer(outBuffer); // PASS FINAL BUFFER
|
||||
freeBuffer(outBuffer); // RELEASE ITEMS
|
||||
/*********************/
|
||||
}
|
||||
|
||||
void
|
||||
handleSAXBufferRotation(Buffer *inBufferPtr)
|
||||
{
|
||||
printf("Buffer full, SAX-ing\n\n");
|
||||
|
||||
Buffer inBuffer = *inBufferPtr;
|
||||
Buffer outBuffer; // OUTPUT BUFFER HOLDER
|
||||
// above pointer is assigned a buffer in either of the below cases
|
||||
|
||||
int outLength = ceil((float)inBuffer.length/AGGREGATION_GROUP_SIZE); // CALCULATE NUMBER OF OUTPUT ELEMENTS
|
||||
outBuffer = getBuffer(outLength); // CREATE OUTPUT BUFFER
|
||||
|
||||
inBuffer.stats = calculateStdDev(inBuffer.items, inBuffer.length); // GET BUFFER STATISTICS
|
||||
outBuffer.stats = inBuffer.stats;
|
||||
|
||||
normaliseBuffer(inBuffer); // Z NORMALISATION
|
||||
aggregateBuffer(inBuffer, outBuffer, AGGREGATION_GROUP_SIZE); // PAA
|
||||
|
||||
/*********************/
|
||||
handleFinalBuffer(outBuffer); // PASS FINAL BUFFER
|
||||
@ -168,5 +201,12 @@ handleFinalBuffer(Buffer buffer)
|
||||
printBuffer(buffer);putchar('\n');
|
||||
printf("Mean: ");putFloat(buffer.stats.mean);putchar('\n');
|
||||
printf("Std Dev: ");putFloat(buffer.stats.std);putchar('\n');putchar('\n');
|
||||
|
||||
#ifdef SAX
|
||||
char* saxString = stringifyBuffer(buffer);
|
||||
printf("SAX: %s\n\n", saxString);
|
||||
|
||||
free(saxString);
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
Binary file not shown.
93
Coursework/sax.h
Normal file
93
Coursework/sax.h
Normal file
@ -0,0 +1,93 @@
|
||||
#ifndef _SAX_GUARD
|
||||
#define _SAX_GUARD
|
||||
|
||||
#define SAX_CHAR_START 'a'
|
||||
|
||||
#ifndef SAX_BREAKPOINTS
|
||||
#define SAX_BREAKPOINTS 4
|
||||
#endif
|
||||
|
||||
// Could have used a 2d array for breakpoints, index by number of breakpoints
|
||||
|
||||
// Since the number of boundaries is known at compile-time, save these lookup calls by
|
||||
// defining as as constant 1D arrays
|
||||
|
||||
#if SAX_BREAKPOINTS == 3
|
||||
const float breakPoints[] = {-0.43, 0.43};
|
||||
#elif SAX_BREAKPOINTS == 4
|
||||
const float breakPoints[] = {-0.67, 0, 0.67};
|
||||
#elif SAX_BREAKPOINTS == 5
|
||||
const float breakPoints[] = {-0.84, -0.25, 0.25, 0.84};
|
||||
#elif SAX_BREAKPOINTS == 6
|
||||
const float breakPoints[] = {-0.97, -0.43, 0, 0.43, 0.97};
|
||||
#elif SAX_BREAKPOINTS == 7
|
||||
const float breakPoints[] = {-1.07, -0.57, -0.18, 0.18, 0.57, 1.07};
|
||||
#elif SAX_BREAKPOINTS == 8
|
||||
const float breakPoints[] = {-1.15, -0.67, -0.32, 0, 0.32, 0.67, 1.15};
|
||||
#elif SAX_BREAKPOINTS == 9
|
||||
const float breakPoints[] = {-1.22, -0.76, -0.43, -0.14, 0.14, 0.43, 0.76, 1.22};
|
||||
#elif SAX_BREAKPOINTS == 10
|
||||
const float breakPoints[] = {-1.28, -0.84, -0.52, -0.25, 0, 0.25, 0.52, 0.84, 1.28};
|
||||
#else
|
||||
#define SAX_BREAKPOINTS 4
|
||||
const float breakPoints[] = {-0.67, 0, 0.67};
|
||||
#endif
|
||||
|
||||
void
|
||||
normaliseBuffer(Buffer bufferIn) // z normalise buffer for SAX
|
||||
{
|
||||
if(bufferIn.stats.std == 0) // error check
|
||||
{
|
||||
printf("Standard deviation of zero, unable to normalise\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int i; // for group number
|
||||
float *inputPtr = bufferIn.items; // cursor for full buffer
|
||||
for(i = 0; i < bufferIn.length; i++)
|
||||
{
|
||||
*inputPtr = (*inputPtr - bufferIn.stats.mean) / bufferIn.stats.std;
|
||||
|
||||
inputPtr++; // increment both cursors
|
||||
}
|
||||
}
|
||||
|
||||
char
|
||||
valueToSAXChar(float inputValue)
|
||||
{
|
||||
float below, above;
|
||||
int i;
|
||||
for(i = 0; i < SAX_BREAKPOINTS; i++)
|
||||
{
|
||||
if(i == 0) // first iter, is less than first breakpoint
|
||||
{
|
||||
if(inputValue < breakPoints[i]) return SAX_CHAR_START + i;
|
||||
}
|
||||
else if(i == SAX_BREAKPOINTS - 1) // last iter, is more than last breakpoint
|
||||
{
|
||||
if(breakPoints[i - 1] < inputValue) return SAX_CHAR_START + i;
|
||||
}
|
||||
else // in between check interval of two breakpoints
|
||||
{
|
||||
if(breakPoints[i - 1] < inputValue < breakPoints[i]) return SAX_CHAR_START + i;
|
||||
}
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
char* // map buffer of normalised floats into SAX chars
|
||||
stringifyBuffer(Buffer bufferIn)
|
||||
{
|
||||
char* outputString = (char*) malloc((bufferIn.length + 1) * sizeof(char));
|
||||
|
||||
int i;
|
||||
for(i = 0; i < bufferIn.length; i++)
|
||||
{
|
||||
outputString[i] = valueToSAXChar(bufferIn.items[i]);
|
||||
}
|
||||
|
||||
outputString[bufferIn.length] = '\0'; // add null terminator
|
||||
return outputString;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user