Metamaterials are artificially designed materials which are composed of periodic subwavelength structures that exhibit exotic properties not found in nature. By manipulating the interaction between light and materials, metamaterials can replicate conventional optical and electromagnetic devices with tremendously reduced thicknesses. However, the main obstacle is the resource requirement to optimize the proposed structure. This difficulty can be mitigated by applying metaheuristic algorithms and machine learning. We demonstrated that two different metamaterials are designed and optimized by employing metaheuristic algorithms and machine learning. Firstly, bitmap metamaterial absorbers are designed via equivalent circuit model and optimized by genetic algorithm. The absorber which covers X-band (8 GHz - 12 GHz) with 99.8% absorption on average is implemented by 4.8 mm thickness. Equivalent circuit of a double-layer bitmap metamaterial can further reduce the thickness to 2.8 mm with -20 dB absorption performance. Also, an ultrathin, angle independent quarter wave plate at 532 nm wavelength is implemented by double-layer slanted rod structure. We proposed a hybrid optimization algorithm which combines neural network and particle swarm optimization (PSO) for this problem. This algorithm optimizes a proposed structure 45 times faster than conventional PSO and reach 30 times better objective function value. The optimized structure shows constant phase retardation from -45 to 45 degrees, and has a thickness of only one micron.